Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
feat(handlers): add Session.ID to Redis Cache.
Browse files Browse the repository at this point in the history
- session ID will be added to redis cache with a ttl

#3
  • Loading branch information
Leo Breuer committed Jul 22, 2023
1 parent e1e94c1 commit 57a100e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions handlers/login.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package handlers

import (
"context"
"encoding/json"
"time"

"gorm.io/gorm"
"miauw.social/auth/database"
"miauw.social/auth/database/models"
"miauw.social/auth/security"
)
Expand Down Expand Up @@ -58,6 +61,8 @@ func UserLogin(db *gorm.DB, rawData []byte) (Response, error) {
}
session := models.Session{UserID: account.ID}
db.Create(&session)
rdb := database.RedisConn()
rdb.SetEx(context.Background(), session.ID.String(), session.UserID.String(), time.Hour*12)
return Response{
Content: UserSessionResponse{SID: session.ID.String()},
Status: ResponseStatus{
Expand Down

0 comments on commit 57a100e

Please sign in to comment.