package auth import ( "dove/config" "dove/session" "github.com/gofiber/fiber/v2" ) func IsAuthenticated(context *fiber.Ctx) bool { activeSession, sessionError := session.Store.Get(context) if sessionError != nil { return false } return activeSession.Get(AuthenticatedKey) != nil } func RequireAuthentication(handler fiber.Handler) fiber.Handler { return func(context *fiber.Ctx) error { if !config.AuthEnabled || IsAuthenticated(context) { return handler(context) } return fiber.ErrUnauthorized } } func Authenticate(context *fiber.Ctx) error { activeSession, sessionError := session.Store.Get(context) if sessionError != nil { return sessionError } activeSession.Set(AuthenticatedKey, true) return activeSession.Save() } func Deauthenticate(context *fiber.Ctx) error { activeSession, sessionError := session.Store.Get(context) if sessionError != nil { return sessionError } return activeSession.Destroy() }