fix: guard against nil session storage

This commit is contained in:
jamesread 2025-10-25 00:20:56 +01:00
parent 956e74a6b3
commit aa8322c354
1 changed files with 6 additions and 2 deletions

View File

@ -45,6 +45,10 @@ func RegisterUserSession(cfg *config.Config, provider string, sid string, userna
} }
} }
if sessionStorage.Providers == nil {
sessionStorage.Providers = make(map[string]*SessionProvider)
}
sessionStorage.Providers[provider].Sessions[sid] = &UserSession{ sessionStorage.Providers[provider].Sessions[sid] = &UserSession{
Username: username, Username: username,
Expiry: time.Now().Unix() + 31556952, // 1 year Expiry: time.Now().Unix() + 31556952, // 1 year
@ -55,8 +59,8 @@ func RegisterUserSession(cfg *config.Config, provider string, sid string, userna
// GetUserSession retrieves a user session // GetUserSession retrieves a user session
func GetUserSession(provider string, sid string) *UserSession { func GetUserSession(provider string, sid string) *UserSession {
sessionStorageMutex.RLock() sessionStorageMutex.Lock()
defer sessionStorageMutex.RUnlock() defer sessionStorageMutex.Unlock()
if sessionStorage.Providers[provider] == nil { if sessionStorage.Providers[provider] == nil {
return nil return nil