mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-09-08 23:50:48 +02:00
27 lines
701 B
Go
27 lines
701 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/starfleetcptn/gomft/components"
|
|
"github.com/starfleetcptn/gomft/internal/auth"
|
|
)
|
|
|
|
// HandleHome handles the GET / route
|
|
func (h *Handlers) HandleHome(c *gin.Context) {
|
|
// Check for JWT token in cookie
|
|
tokenCookie, err := c.Cookie("jwt_token")
|
|
if err == nil && tokenCookie != "" {
|
|
// Token exists, validate it
|
|
claims, err := auth.ValidateToken(tokenCookie, h.JWTSecret)
|
|
if err == nil && claims != nil {
|
|
// Valid token, redirect to dashboard
|
|
c.Redirect(http.StatusFound, "/dashboard")
|
|
return
|
|
}
|
|
}
|
|
|
|
// User is not logged in, show home page
|
|
components.Home(c.Request.Context()).Render(c, c.Writer)
|
|
} |