diff options
| author | Bobby <[email protected]> | 2026-02-11 14:02:58 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-02-11 14:02:58 +0530 |
| commit | d87e08e0fc5911b2ff40604944448e1f0aaa31b7 (patch) | |
| tree | d64dba5b796ad39cb0514293cfd29826b66b8c7c /utils/auth | |
| parent | 2c567dd96712a887b42cf4df3bdaa9f5f2b51a43 (diff) | |
| download | cafe-d87e08e0fc5911b2ff40604944448e1f0aaa31b7.tar.xz cafe-d87e08e0fc5911b2ff40604944448e1f0aaa31b7.zip | |
Implement authentication flow with middleware and controllers, add OpenID discovery URL to server config
Diffstat (limited to 'utils/auth')
| -rw-r--r-- | utils/auth/auth.go | 27 |
1 files changed, 27 insertions, 0 deletions
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) + } +} |
