mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-11-04 08:05:42 +00:00 
			
		
		
		
	refactor: simplify the get cookie data handling
This commit is contained in:
		@@ -227,23 +227,15 @@ func (auth *Auth) GetSessionCookie(c *gin.Context) (types.SessionCookie, error)
 | 
				
			|||||||
		return types.SessionCookie{}, err
 | 
							return types.SessionCookie{}, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Get data
 | 
						// Get data from session
 | 
				
			||||||
	cookieUsername := session.Values["username"]
 | 
						username, usernameOk := session.Values["username"].(string)
 | 
				
			||||||
	cookieProvider := session.Values["provider"]
 | 
						provider, providerOK := session.Values["provider"].(string)
 | 
				
			||||||
	cookieExpiry := session.Values["expiry"]
 | 
						redirectURI, redirectOK := session.Values["redirectURI"].(string)
 | 
				
			||||||
	cookieTotpPending := session.Values["totpPending"]
 | 
						expiry, expiryOk := session.Values["expiry"].(int64)
 | 
				
			||||||
	cookieRedirectURI := session.Values["redirectURI"]
 | 
						totpPending, totpPendingOk := session.Values["totpPending"].(bool)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Convert interfaces to correct types
 | 
						if !usernameOk || !providerOK || !expiryOk || !redirectOK || !totpPendingOk {
 | 
				
			||||||
	username, usernameOk := cookieUsername.(string)
 | 
							log.Warn().Msg("Session cookie is missing data")
 | 
				
			||||||
	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")
 | 
					 | 
				
			||||||
		return types.SessionCookie{}, nil
 | 
							return types.SessionCookie{}, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user