summaryrefslogtreecommitdiff
path: root/nexus/sessions/functions.go
diff options
context:
space:
mode:
Diffstat (limited to 'nexus/sessions/functions.go')
-rw-r--r--nexus/sessions/functions.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/nexus/sessions/functions.go b/nexus/sessions/functions.go
new file mode 100644
index 0000000..4baedb1
--- /dev/null
+++ b/nexus/sessions/functions.go
@@ -0,0 +1,55 @@
+package sessions
+
+import (
+ "nexus/utils/collections"
+
+ "github.com/gofiber/fiber/v2/middleware/session"
+ "github.com/google/uuid"
+)
+
+func CreateSession(sess *session.Session, accountID uuid.UUID) error {
+ return Set(sess, SessionAccountIDKey, accountID.String())
+}
+
+func DestroySession(sess *session.Session) error {
+ return Delete(sess, SessionAccountIDKey)
+}
+
+func GetSessionAccountID(sess *session.Session) (uuid.UUID, bool) {
+ value := Get(sess, SessionAccountIDKey)
+ if value == nil {
+ return uuid.Nil, false
+ }
+
+ str, ok := value.(string)
+ if !ok {
+ return uuid.Nil, false
+ }
+
+ id, err := uuid.Parse(str)
+ if err != nil {
+ return uuid.Nil, false
+ }
+
+ return id, true
+}
+
+func SetFlash(sess *session.Session, data collections.Record[string, any]) error {
+ return Set(sess, SessionFlashKey, data)
+}
+
+func GetFlash(sess *session.Session) collections.Record[string, any] {
+ value := Get(sess, SessionFlashKey)
+ if value == nil {
+ return nil
+ }
+ m, ok := value.(collections.Record[string, any])
+ if !ok {
+ return nil
+ }
+ return m
+}
+
+func ClearFlash(sess *session.Session) error {
+ return Delete(sess, SessionFlashKey)
+}