fix: env + session to new db format

This commit is contained in:
Lakhan Samani
2022-01-21 12:18:07 +05:30
parent 38419a4ef4
commit 13c038effd
17 changed files with 732 additions and 3 deletions

View File

@@ -1,7 +1,10 @@
package utils
import (
"log"
"github.com/authorizerdev/authorizer/server/db"
"github.com/authorizerdev/authorizer/server/db/models"
"github.com/gin-gonic/gin"
)
@@ -16,13 +19,18 @@ func StringSliceContains(s []string, e string) bool {
}
// SaveSessionInDB saves sessions generated for a given user with meta information
// Not store token here as that could be security breach
// Do not store token here as that could be security breach
func SaveSessionInDB(userId string, c *gin.Context) {
sessionData := db.Session{
sessionData := models.Session{
UserID: userId,
UserAgent: GetUserAgent(c.Request),
IP: GetIP(c.Request),
}
db.Mgr.AddSession(sessionData)
err := db.Provider.AddSession(&sessionData)
if err != nil {
log.Println("=> error saving session in db:", err)
} else {
log.Println("=> session saved in db:", sessionData)
}
}