fix: make an attempt to look for the token before adding to db
This commit is contained in:
parent
a7ac5a5b72
commit
f11b285d4e
|
@ -62,6 +62,13 @@ func generateAndSaveLoginToken(accountID uint, maxAge time.Duration) (string, er
|
|||
Expiration: claim.ExpiresAt(),
|
||||
}
|
||||
|
||||
existingSession := model.LoginSession{}
|
||||
|
||||
err = db.Get().Where("token = ?", token).First(&existingSession).Error
|
||||
if err == nil {
|
||||
return token, nil
|
||||
}
|
||||
|
||||
if err := db.Get().Create(&session).Error; err != nil {
|
||||
if strings.Contains(err.Error(), "Duplicate entry") {
|
||||
return token, nil
|
||||
|
|
Loading…
Reference in New Issue