From 8e84e59c2fb99cf52dd8f9069254fcd56eadeca4 Mon Sep 17 00:00:00 2001 From: Stavros Date: Sun, 6 Apr 2025 20:53:24 +0300 Subject: [PATCH] refactor: simplify the get cookie data handling --- internal/auth/auth.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/internal/auth/auth.go b/internal/auth/auth.go index 327f637..5857c78 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -227,23 +227,15 @@ func (auth *Auth) GetSessionCookie(c *gin.Context) (types.SessionCookie, error) return types.SessionCookie{}, err } - // Get data - cookieUsername := session.Values["username"] - cookieProvider := session.Values["provider"] - cookieExpiry := session.Values["expiry"] - cookieTotpPending := session.Values["totpPending"] - cookieRedirectURI := session.Values["redirectURI"] + // Get data from session + username, usernameOk := session.Values["username"].(string) + provider, providerOK := session.Values["provider"].(string) + redirectURI, redirectOK := session.Values["redirectURI"].(string) + expiry, expiryOk := session.Values["expiry"].(int64) + totpPending, totpPendingOk := session.Values["totpPending"].(bool) - // Convert interfaces to correct types - username, usernameOk := cookieUsername.(string) - provider, providerOk := cookieProvider.(string) - expiry, expiryOk := cookieExpiry.(int64) - totpPending, totpPendingOk := cookieTotpPending.(bool) - redirectURI, redirectURIOk := cookieRedirectURI.(string) - - // Check if the cookie is invalid - if !usernameOk || !providerOk || !expiryOk || !totpPendingOk || !redirectURIOk { - log.Warn().Msg("Session cookie invalid") + if !usernameOk || !providerOK || !expiryOk || !redirectOK || !totpPendingOk { + log.Warn().Msg("Session cookie is missing data") return types.SessionCookie{}, nil }