summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorBobby <[email protected]>2025-12-22 12:41:27 +0530
committerBobby <[email protected]>2025-12-22 12:41:27 +0530
commitf17d9142781eb1a659ea53311d9225b244ad209c (patch)
tree1b03e1f96cca8559ad1a7e37e74279136a3bf157 /utils
parented74f2cffa902a3e9aeb614f8dcf65f04658a597 (diff)
downloadlain-f17d9142781eb1a659ea53311d9225b244ad209c.tar.xz
lain-f17d9142781eb1a659ea53311d9225b244ad209c.zip
better auth and error handler setup
Diffstat (limited to 'utils')
-rw-r--r--utils/auth/auth.go9
-rw-r--r--utils/shortcuts/redirect.go6
2 files changed, 15 insertions, 0 deletions
diff --git a/utils/auth/auth.go b/utils/auth/auth.go
index 4b0fbff..8fba2d2 100644
--- a/utils/auth/auth.go
+++ b/utils/auth/auth.go
@@ -15,3 +15,12 @@ func IsAuthenticated(context *fiber.Ctx) bool {
email := session.Get("email")
return email != nil
}
+
+func RequireAuthentication(handler fiber.Handler) fiber.Handler {
+ return func(context *fiber.Ctx) error {
+ if !IsAuthenticated(context) {
+ return fiber.ErrUnauthorized
+ }
+ return handler(context)
+ }
+}
diff --git a/utils/shortcuts/redirect.go b/utils/shortcuts/redirect.go
index aa760dc..77e1959 100644
--- a/utils/shortcuts/redirect.go
+++ b/utils/shortcuts/redirect.go
@@ -21,3 +21,9 @@ func RedirectWithStatus(ctx *fiber.Ctx, routeName string, statusCode int) error
}
return ctx.Redirect(path, statusCode)
}
+
+func RedirectTo(route string) fiber.Handler {
+ return func(ctx *fiber.Ctx) error {
+ return Redirect(ctx, route)
+ }
+}