Deletes the user's cookie if it expires or something fails.

This commit is contained in:
Zeni Kim 2026-09-12 22:17:24 -05:00
parent f37911847e
commit fda18abc89

View file

@ -125,15 +125,21 @@ func AppSignout(c *core.Context) *core.Response {
// get cookie // get cookie
usercookie, err := c.GetCookie() usercookie, err := c.GetCookie()
if err != nil { if err != nil {
// the cookie could not be read/decrypted, still make sure it is removed from the client
core.ClearCookie(c.Response.HttpResponseWriter)
return c.Response.Redirect("/applogin") return c.Response.Redirect("/applogin")
} }
token = usercookie.Token token = usercookie.Token
if token == "" { if token == "" {
// no token present, still clear any (possibly present) cookie on the client
core.ClearCookie(c.Response.HttpResponseWriter)
return c.Response.Redirect("/applogin") return c.Response.Redirect("/applogin")
} }
payload, err := c.GetJWT().DecodeToken(token) payload, err := c.GetJWT().DecodeToken(token)
if err != nil { if err != nil {
// the token is invalid, clear the cookie on the client
core.ClearCookie(c.Response.HttpResponseWriter)
return c.Response.Redirect("/applogin") return c.Response.Redirect("/applogin")
} }
userAgent := c.GetUserAgent() userAgent := c.GetUserAgent()
@ -141,9 +147,15 @@ func AppSignout(c *core.Context) *core.Response {
err = c.GetCache().Delete(hashedCacheKey) err = c.GetCache().Delete(hashedCacheKey)
if err != nil { if err != nil {
// failed to invalidate the cached token, still clear the cookie on the client
core.ClearCookie(c.Response.HttpResponseWriter)
return c.Response.Redirect("/applogin") return c.Response.Redirect("/applogin")
} }
// successful signout: the token is removed from the cache, also clear
// the cookie on the client before the final redirect
core.ClearCookie(c.Response.HttpResponseWriter)
return c.Response.Redirect("/applogin") return c.Response.Redirect("/applogin")
} }