diff options
| author | Bobby <[email protected]> | 2026-01-20 14:22:24 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-01-20 14:22:24 +0530 |
| commit | 2a513445a50bbe0d3a5cb13784c8ed68e1c367fa (patch) | |
| tree | da67de8714927f523612882f0ba4787d94efa078 /session/functions.go | |
| parent | a04faab2a7c031b95e6e7553f9921c3bada2bc08 (diff) | |
| download | cafe-2a513445a50bbe0d3a5cb13784c8ed68e1c367fa.tar.xz cafe-2a513445a50bbe0d3a5cb13784c8ed68e1c367fa.zip | |
Add session management with PostgreSQL storage and utility functions
Diffstat (limited to 'session/functions.go')
| -rw-r--r-- | session/functions.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/session/functions.go b/session/functions.go new file mode 100644 index 0000000..286ebbb --- /dev/null +++ b/session/functions.go @@ -0,0 +1,27 @@ +package session + +import "github.com/gofiber/fiber/v2" + +const userIDKey = "user_id" + +func CreateSession(ctx *fiber.Ctx, userID uint) error { + return Set(ctx, userIDKey, userID) +} + +func DestroySession(ctx *fiber.Ctx) error { + return Delete(ctx, userIDKey) +} + +func GetSessionUserID(ctx *fiber.Ctx) (uint, error) { + value, err := Get(ctx, userIDKey) + if err != nil || value == nil { + return 0, err + } + + userID, ok := value.(uint) + if !ok { + return 0, nil + } + + return userID, nil +} |
