refactor(response): remove hardcoded cookie path from refresh token functions
Eliminated the hardcoded path "/auth" from the SendRefreshTokenCookie functions and the DeleteAllAuthCookies function. This change enhances flexibility by allowing the cookie path to be managed more dynamically in the future.
This commit is contained in:
parent
31e6bd8ec8
commit
032488512a
1 changed files with 2 additions and 6 deletions
|
|
@ -408,7 +408,6 @@ func SendAccessTokenCookieWithDuration(c *gin.Context, accessToken string, durat
|
||||||
func SendRefreshTokenCookie(c *gin.Context, refreshToken string, maxAge int) {
|
func SendRefreshTokenCookie(c *gin.Context, refreshToken string, maxAge int) {
|
||||||
options := NewSecureCookieOptions().
|
options := NewSecureCookieOptions().
|
||||||
WithMaxAge(maxAge).
|
WithMaxAge(maxAge).
|
||||||
WithPath("/auth").
|
|
||||||
WithSameSite("Strict")
|
WithSameSite("Strict")
|
||||||
SendSecureCookieWithOptions(c, "refresh_token", refreshToken, options)
|
SendSecureCookieWithOptions(c, "refresh_token", refreshToken, options)
|
||||||
}
|
}
|
||||||
|
|
@ -417,7 +416,6 @@ func SendRefreshTokenCookie(c *gin.Context, refreshToken string, maxAge int) {
|
||||||
func SendRefreshTokenCookieWithExpiry(c *gin.Context, refreshToken string, expires time.Time) {
|
func SendRefreshTokenCookieWithExpiry(c *gin.Context, refreshToken string, expires time.Time) {
|
||||||
options := NewSecureCookieOptions().
|
options := NewSecureCookieOptions().
|
||||||
WithExpires(expires).
|
WithExpires(expires).
|
||||||
WithPath("/auth").
|
|
||||||
WithSameSite("Strict")
|
WithSameSite("Strict")
|
||||||
SendSecureCookieWithOptions(c, "refresh_token", refreshToken, options)
|
SendSecureCookieWithOptions(c, "refresh_token", refreshToken, options)
|
||||||
}
|
}
|
||||||
|
|
@ -426,7 +424,6 @@ func SendRefreshTokenCookieWithExpiry(c *gin.Context, refreshToken string, expir
|
||||||
func SendRefreshTokenCookieWithDuration(c *gin.Context, refreshToken string, duration time.Duration) {
|
func SendRefreshTokenCookieWithDuration(c *gin.Context, refreshToken string, duration time.Duration) {
|
||||||
options := NewSecureCookieOptions().
|
options := NewSecureCookieOptions().
|
||||||
WithDuration(duration).
|
WithDuration(duration).
|
||||||
WithPath("/auth").
|
|
||||||
WithSameSite("Strict")
|
WithSameSite("Strict")
|
||||||
SendSecureCookieWithOptions(c, "refresh_token", refreshToken, options)
|
SendSecureCookieWithOptions(c, "refresh_token", refreshToken, options)
|
||||||
}
|
}
|
||||||
|
|
@ -442,10 +439,9 @@ func DeleteAllAuthCookies(c *gin.Context) {
|
||||||
DeleteSecureCookie(c, "session_id")
|
DeleteSecureCookie(c, "session_id")
|
||||||
DeleteSecureCookie(c, "access_token")
|
DeleteSecureCookie(c, "access_token")
|
||||||
|
|
||||||
// Also delete refresh token with its specific path
|
// Also delete refresh token cookie
|
||||||
options := NewSecureCookieOptions().
|
options := NewSecureCookieOptions().
|
||||||
WithMaxAge(-1).
|
WithMaxAge(-1)
|
||||||
WithPath("/auth")
|
|
||||||
SendSecureCookieWithOptions(c, "refresh_token", "", options)
|
SendSecureCookieWithOptions(c, "refresh_token", "", options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue