From d87e08e0fc5911b2ff40604944448e1f0aaa31b7 Mon Sep 17 00:00:00 2001 From: Bobby <30593201+luciferreeves@users.noreply.github.com> Date: Wed, 11 Feb 2026 14:02:58 +0530 Subject: Implement authentication flow with middleware and controllers, add OpenID discovery URL to server config --- utils/auth/auth.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 utils/auth/auth.go (limited to 'utils') diff --git a/utils/auth/auth.go b/utils/auth/auth.go new file mode 100644 index 0000000..3cee3a4 --- /dev/null +++ b/utils/auth/auth.go @@ -0,0 +1,27 @@ +package auth + +import ( + "cafe/session" + "cafe/utils/shortcuts" + + "github.com/gofiber/fiber/v2" +) + +func IsAuthenticated(context *fiber.Ctx) bool { + session, err := session.Store.Get(context) + if err != nil { + return false + } + + username := session.Get("username") + return username != nil +} + +func RequireAuthentication(handler fiber.Handler) fiber.Handler { + return func(context *fiber.Ctx) error { + if !IsAuthenticated(context) { + return shortcuts.Redirect(context, "auth.authenticate") + } + return handler(context) + } +} -- cgit v1.2.3