fix: coderabbit suggestions

This commit is contained in:
Stavros
2025-08-27 14:04:26 +03:00
parent dc733a71c1
commit 32c7e8e045
4 changed files with 16 additions and 4 deletions

View File

@@ -169,8 +169,18 @@ func (controller *OAuthController) oauthCallbackHandler(c *gin.Context) {
name = fmt.Sprintf("%s (%s)", utils.Capitalize(strings.Split(user.Email, "@")[0]), strings.Split(user.Email, "@")[1])
}
var usename string
if user.PreferredUsername != "" {
log.Debug().Msg("Using preferred username from OAuth provider")
usename = user.PreferredUsername
} else {
log.Debug().Msg("No preferred username from OAuth provider, using pseudo username")
usename = strings.Replace(user.Email, "@", "_", -1)
}
controller.Auth.CreateSessionCookie(c, &config.SessionCookie{
Username: user.PreferredUsername,
Username: usename,
Name: name,
Email: user.Email,
Provider: req.Provider,

View File

@@ -1,7 +1,7 @@
package model
type Session struct {
UUID string `gorm:"column:uuid"`
UUID string `gorm:"column:uuid;primaryKey"`
Username string `gorm:"column:username"`
Email string `gorm:"column:email"`
Name string `gorm:"column:name"`

View File

@@ -222,13 +222,13 @@ func (auth *AuthService) CreateSessionCookie(c *gin.Context, data *config.Sessio
}
func (auth *AuthService) DeleteSessionCookie(c *gin.Context) error {
session, err := auth.GetSessionCookie(c)
cookie, err := c.Cookie(auth.Config.SessionCookieName)
if err != nil {
return err
}
res := auth.Database.Unscoped().Where("uuid = ?", session.UUID).Delete(&model.Session{})
res := auth.Database.Unscoped().Where("uuid = ?", cookie).Delete(&model.Session{})
if res.Error != nil {
return res.Error

View File

@@ -39,6 +39,8 @@ func (ds *DatabaseService) Init() error {
return err
}
sqlDB.SetMaxOpenConns(1)
err = ds.migrateDatabase(sqlDB)
if err != nil && err != migrate.ErrNoChange {