From c02501329a0f23c6f71fa9305e1d94c008742c5e Mon Sep 17 00:00:00 2001 From: Ruidy Date: Sat, 20 Sep 2025 16:08:24 +0200 Subject: [PATCH] feat: unify auth templates --- internal/server/server.go | 1 + internal/server/views.go | 22 ++- web/templates/auth_base.html | 272 ++++++++++++++++++++++++++++++++ web/templates/dashboard.html | 38 +---- web/templates/login.html | 149 ++++++++++------- web/templates/signup.html | 155 ++++++++++++------ web/templates/unauthorized.html | 25 +-- 7 files changed, 490 insertions(+), 172 deletions(-) create mode 100644 web/templates/auth_base.html diff --git a/internal/server/server.go b/internal/server/server.go index 72c62bf..a270a10 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -32,6 +32,7 @@ type Server struct { func New(cfg config.Config, logger *slog.Logger) (*Server, error) { tmpl, err := template.ParseFS( web.Templates, + "templates/auth_base.html", "templates/login.html", "templates/dashboard.html", "templates/signup.html", diff --git a/internal/server/views.go b/internal/server/views.go index c001b81..a7ea11d 100644 --- a/internal/server/views.go +++ b/internal/server/views.go @@ -17,6 +17,8 @@ func (s *Server) render(w http.ResponseWriter, name string, data any) { // PageData contains fields shared by the templates for now. type PageData struct { + Title string + View string Email string Error string Info string @@ -26,17 +28,29 @@ type PageData struct { } func newLoginData(email, errMsg, token string) PageData { - return PageData{Email: email, Error: errMsg, CSRFToken: token} + return PageData{Title: "Sign in · Auth Demo", View: "login", Email: email, Error: errMsg, CSRFToken: token} } func newUnauthorizedData(errMsg, token string) PageData { - return PageData{Error: errMsg, CSRFToken: token} + return PageData{ + Title: "Access denied · Auth Demo", + View: "unauthorized", + Error: errMsg, + CSRFToken: token, + } } func newDashboardData(email, token, createdAt, createdAtISO string) PageData { - return PageData{Email: email, CSRFToken: token, CreatedAt: createdAt, CreatedAtISO: createdAtISO} + return PageData{ + Title: "Dashboard · Auth Demo", + View: "dashboard", + Email: email, + CSRFToken: token, + CreatedAt: createdAt, + CreatedAtISO: createdAtISO, + } } func newSignupData(email, errMsg, token string) PageData { - return PageData{Email: email, Error: errMsg, CSRFToken: token} + return PageData{Title: "Create account · Auth Demo", View: "signup", Email: email, Error: errMsg, CSRFToken: token} } diff --git a/web/templates/auth_base.html b/web/templates/auth_base.html new file mode 100644 index 0000000..8d0c69c --- /dev/null +++ b/web/templates/auth_base.html @@ -0,0 +1,272 @@ +{{define "auth_base"}} + + + + + + {{if .Title}}{{.Title}}{{else}}Auth Demo{{end}} + + + + +
+
+
+ +
+
“Simply all the tools that my team and I need.”
+ Karen Yue · Director of Digital Marketing Technology +
+
+
+ {{if eq .View "login"}} + {{template "login_content" .}} + {{else if eq .View "signup"}} + {{template "signup_content" .}} + {{else if eq .View "dashboard"}} + {{template "dashboard_content" .}} + {{else if eq .View "unauthorized"}} + {{template "unauthorized_content" .}} + {{else}} + {{template "auth_default_content" .}} + {{end}} +
+
+
+ + +{{end}} + +{{define "auth_default_content"}} +
+

Authentication

+

Pick an auth flow to continue.

+
+{{end}} + +{{define "dashboard_content"}} +
+

Welcome back

+

You're signed in as {{.Email}}.

+
+
+ {{if .CreatedAt}} +

+ Member since + . +

+ {{end}} +

This dashboard will grow alongside the authentication features.

+
+
+ + +
+{{end}} + +{{define "unauthorized_content"}} +
+

Access denied

+

{{if .Error}}{{.Error}}{{else}}You do not have permission to view that page.{{end}}

+
+ +{{end}} diff --git a/web/templates/dashboard.html b/web/templates/dashboard.html index 9285aef..3379c1c 100644 --- a/web/templates/dashboard.html +++ b/web/templates/dashboard.html @@ -1,35 +1,3 @@ - - - - - - Dashboard - - - -
-

Welcome

-
-

You are signed in as {{.Email}}.

- {{if .CreatedAt}} -

- Member since - . -

- {{end}} -

- This placeholder dashboard will evolve as we flesh out the auth flow. -

-
-
- - -
-
-
-
- - +{{define "dashboard.html"}} + {{template "auth_base" .}} +{{end}} diff --git a/web/templates/login.html b/web/templates/login.html index f20f373..d0d0b07 100644 --- a/web/templates/login.html +++ b/web/templates/login.html @@ -1,60 +1,89 @@ - - - - - - Auth Demo - - - -
-

Sign in

-

Authenticate with the demo credentials below to view the dashboard.

-
-
Demo account
-

- Email: user@example.com
- Password: - - Password123 -

-
- {{if .Error}} -
- Unable to sign in: {{.Error}} -
- {{end}} -
- - - - - - -
-

- Need an account? - Create one now. -

-
- - +{{define "login.html"}} + {{template "auth_base" .}} +{{end}} + +{{define "login_content"}} +
+

Welcome back to Nucleus

+

Build your design system effortlessly with our powerful component library.

+
+
+ Demo account access
+ Email: user@example.com · Password: Password123 +
+ {{if .Error}} + + {{end}} +
+ + + +
+ Forgot password? + +
+
+ +
or
+ +
+
+ +{{end}} diff --git a/web/templates/signup.html b/web/templates/signup.html index e796462..963f9a7 100644 --- a/web/templates/signup.html +++ b/web/templates/signup.html @@ -1,51 +1,104 @@ - - - - - - Create Account - - - -
-

Sign up

-

Provide your email and a strong password to create an account.

- {{if .Error}} -
- Unable to sign up: {{.Error}} -
- {{end}} -
- - - - - - -
-

- Already registered? - Return to sign in. -

-
- - +{{define "signup.html"}} + {{template "auth_base" .}} +{{end}} + +{{define "signup_content"}} +
+

Create your account

+

Join Nucleus UI and start designing with ease.

+
+ {{if .Info}} +
+
Heads-up
+

{{.Info}}

+
+ {{end}} + {{if .Error}} + + {{end}} +
+ + + + + +
+ +
or
+ +
+
+ +{{end}} diff --git a/web/templates/unauthorized.html b/web/templates/unauthorized.html index d8d7787..eecfe71 100644 --- a/web/templates/unauthorized.html +++ b/web/templates/unauthorized.html @@ -1,22 +1,3 @@ - - - - - - Unauthorized - - - -
-

Unauthorized

-

- {{if .Error}}{{.Error}}{{else}}You do not have permission to view that - page.{{end}} -

- Back to safety -
- - +{{define "unauthorized.html"}} + {{template "auth_base" .}} +{{end}}