fix: add redirect url to logout
This commit is contained in:
parent
f5bdc8db39
commit
60cd317e67
|
@ -2,6 +2,7 @@ package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/cookie"
|
"github.com/authorizerdev/authorizer/server/cookie"
|
||||||
"github.com/authorizerdev/authorizer/server/crypto"
|
"github.com/authorizerdev/authorizer/server/crypto"
|
||||||
|
@ -12,6 +13,7 @@ import (
|
||||||
// Handler to logout user
|
// Handler to logout user
|
||||||
func LogoutHandler() gin.HandlerFunc {
|
func LogoutHandler() gin.HandlerFunc {
|
||||||
return func(gc *gin.Context) {
|
return func(gc *gin.Context) {
|
||||||
|
redirectURL := strings.TrimSpace(gc.Query("redirect_url"))
|
||||||
// get fingerprint hash
|
// get fingerprint hash
|
||||||
fingerprintHash, err := cookie.GetSession(gc)
|
fingerprintHash, err := cookie.GetSession(gc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -34,8 +36,12 @@ func LogoutHandler() gin.HandlerFunc {
|
||||||
sessionstore.RemoveState(fingerPrint)
|
sessionstore.RemoveState(fingerPrint)
|
||||||
cookie.DeleteSession(gc)
|
cookie.DeleteSession(gc)
|
||||||
|
|
||||||
gc.JSON(http.StatusOK, gin.H{
|
if redirectURL != "" {
|
||||||
"message": "Logged out successfully",
|
gc.Redirect(http.StatusPermanentRedirect, redirectURL)
|
||||||
})
|
} else {
|
||||||
|
gc.JSON(http.StatusOK, gin.H{
|
||||||
|
"message": "Logged out successfully",
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user