summaryrefslogtreecommitdiff
path: root/database/users.go
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth@simponic.xyz>2024-04-06 13:36:13 -0600
committerElizabeth Hunt <elizabeth@simponic.xyz>2024-04-06 13:36:13 -0600
commit5177735b835289c8437799536d3654e5ab142fa3 (patch)
treeaa5a0c9588ca7b1b97ccd6c4f0cf245d2c3ac162 /database/users.go
parentae640a253edb5935380975fb07430e910a83b340 (diff)
downloadhatecomputers.club-5177735b835289c8437799536d3654e5ab142fa3.tar.gz
hatecomputers.club-5177735b835289c8437799536d3654e5ab142fa3.zip
finish auth tests
Diffstat (limited to 'database/users.go')
-rw-r--r--database/users.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/database/users.go b/database/users.go
index 5cebb8f..6f9456e 100644
--- a/database/users.go
+++ b/database/users.go
@@ -111,6 +111,18 @@ func DeleteSession(dbConn *sql.DB, sessionId string) error {
return nil
}
+func SaveSession(dbConn *sql.DB, session *UserSession) (*UserSession, error) {
+ log.Println("saving session", session.ID)
+
+ _, err := dbConn.Exec(`INSERT OR REPLACE INTO user_sessions (id, user_id, expire_at) VALUES (?, ?, ?);`, session.ID, session.UserID, session.ExpireAt)
+ if err != nil {
+ log.Println(err)
+ return nil, err
+ }
+
+ return session, nil
+}
+
func RefreshSession(dbConn *sql.DB, sessionId string) (*UserSession, error) {
newExpireAt := time.Now().Add(ExpiryDuration)