Actually fucking save the fucking ID
This commit is contained in:
21
esi_sso.go
21
esi_sso.go
@@ -29,7 +29,7 @@ const (
|
||||
)
|
||||
|
||||
type Character struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
ID int64 `gorm:"primaryKey"` // EVE character ID from JWT token
|
||||
CharacterName string `gorm:"uniqueIndex"`
|
||||
AccessToken string
|
||||
RefreshToken string
|
||||
@@ -125,6 +125,20 @@ func (s *SSO) GetCharacter(ctx context.Context, characterName string) (Character
|
||||
}
|
||||
} else {
|
||||
logger.Debug("Found existing token for character %s, expires at %v", characterName, char.ExpiresAt)
|
||||
// Check if character ID is missing (old record)
|
||||
if char.ID == 0 {
|
||||
logger.Info("Character ID missing for %s, extracting from token", characterName)
|
||||
_, eveCharID := parseTokenCharacter(char.AccessToken)
|
||||
if eveCharID > 0 {
|
||||
char.ID = eveCharID
|
||||
logger.Debug("Updating character %s with ID: %d", characterName, eveCharID)
|
||||
if err := s.db.SaveCharacter(char); err != nil {
|
||||
logger.Warning("Failed to update character %s with ID: %v", characterName, err)
|
||||
}
|
||||
} else {
|
||||
logger.Warning("Failed to extract character ID from token for %s", characterName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if token needs refresh
|
||||
@@ -203,7 +217,10 @@ func (s *SSO) startAuthFlow(ctx context.Context, characterName string) error {
|
||||
|
||||
// Save token to DB
|
||||
char.CharacterName = characterName
|
||||
logger.Debug("Saving token to database for character %s", characterName)
|
||||
// Extract and set EVE character ID as primary key
|
||||
_, eveCharID := parseTokenCharacter(char.AccessToken)
|
||||
char.ID = eveCharID
|
||||
logger.Debug("Saving token to database for character %s (EVE ID: %d)", characterName, eveCharID)
|
||||
if err := s.db.SaveCharacter(char); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user