Hayden Hargreaves 5e07383ab0 (FIX): Fixed the JWT handling, no need to fail.
We don't need to fail, but we do need a way to know when a user is
logged in. The new domain(server) function IsLoggedIn will do just that!
2025-06-15 20:34:03 -07:00

27 lines
658 B
Go

package domain
import (
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt/v5"
domainAuth "github.com/haydenhargreaves/Potion/internal/domain/auth"
domainUser "github.com/haydenhargreaves/Potion/internal/domain/user"
)
type InjectedDependencies struct {
UserService domainUser.UserService
AuthService domainAuth.AuthService
}
type JwtClaims struct {
UserId int `json:"id"`
Email string `json:"email"`
jwt.RegisteredClaims
}
// IsLoggedIn checks the cookies in a request and returns whether the user is logged in.
func IsLoggedIn(ctx *gin.Context) bool {
_, id := ctx.Get("userId")
_, email := ctx.Get("userEmail")
return id && email
}