Deletes the user's cookie if it expires or something fails.
This commit is contained in:
parent
f37911847e
commit
fda18abc89
1 changed files with 12 additions and 0 deletions
|
|
@ -125,15 +125,21 @@ func AppSignout(c *core.Context) *core.Response {
|
|||
// get cookie
|
||||
usercookie, err := c.GetCookie()
|
||||
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")
|
||||
}
|
||||
token = usercookie.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")
|
||||
}
|
||||
payload, err := c.GetJWT().DecodeToken(token)
|
||||
if err != nil {
|
||||
// the token is invalid, clear the cookie on the client
|
||||
core.ClearCookie(c.Response.HttpResponseWriter)
|
||||
return c.Response.Redirect("/applogin")
|
||||
}
|
||||
userAgent := c.GetUserAgent()
|
||||
|
|
@ -141,9 +147,15 @@ func AppSignout(c *core.Context) *core.Response {
|
|||
|
||||
err = c.GetCache().Delete(hashedCacheKey)
|
||||
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")
|
||||
}
|
||||
|
||||
// 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")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue