diff --git a/cmd/server/main.go b/cmd/server/main.go index d05babc..de76c9f 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -38,8 +38,18 @@ func main() { // Routes e.GET("/", func(c echo.Context) error { + tokenString := getToken(c) + loggedIn := false + if tokenString != "" { + token, err := jwtgo.Parse(tokenString, func(token *jwtgo.Token) (interface{}, error) { + return []byte(cfg.JWTSecret), nil + }) + if err == nil && token.Valid { + loggedIn = true + } + } var buf bytes.Buffer - err := templates.Index().Render(c.Request().Context(), &buf) + err := templates.Index(loggedIn).Render(c.Request().Context(), &buf) if err != nil { return err } diff --git a/templates/index.templ b/templates/index.templ index 1cd55d2..930a3bb 100644 --- a/templates/index.templ +++ b/templates/index.templ @@ -1,6 +1,6 @@ package templates -templ Index() { +templ Index(loggedIn bool) { @@ -204,60 +204,39 @@ templ Index() { -
-
-
-

Join Bookmann Today

-

Create your account or sign in to start managing your ebook library

-
- -
-
-

Login

-
-
-
- - -
-
- - -
- -
-
+ if !loggedIn { +
+
+
+

Join Bookmann Today

+

Sign in to start managing your ebook library

-
-

Create Account

-
-
-
- - +
+
+

Login

+ +
+
+ + +
+
+ + +
+
-
- - -
-
- - -
- -
- + +
-
-
+
+
-
+ }