From f11b285d4e255c1c4c95f6ac15aa904d7a5730e4 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 4 Aug 2023 12:54:45 -0400 Subject: [PATCH] fix: make an attempt to look for the token before adding to db --- service/auth/util.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/service/auth/util.go b/service/auth/util.go index ce85034..baa87e1 100644 --- a/service/auth/util.go +++ b/service/auth/util.go @@ -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