From 60cd317e67923cf538e3c9aff8047ea3b9ab5948 Mon Sep 17 00:00:00 2001 From: Lakhan Samani Date: Tue, 8 Mar 2022 21:32:42 +0530 Subject: [PATCH] fix: add redirect url to logout --- server/handlers/logout.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server/handlers/logout.go b/server/handlers/logout.go index f3090aa..14c1730 100644 --- a/server/handlers/logout.go +++ b/server/handlers/logout.go @@ -2,6 +2,7 @@ package handlers import ( "net/http" + "strings" "github.com/authorizerdev/authorizer/server/cookie" "github.com/authorizerdev/authorizer/server/crypto" @@ -12,6 +13,7 @@ import ( // Handler to logout user func LogoutHandler() gin.HandlerFunc { return func(gc *gin.Context) { + redirectURL := strings.TrimSpace(gc.Query("redirect_url")) // get fingerprint hash fingerprintHash, err := cookie.GetSession(gc) if err != nil { @@ -34,8 +36,12 @@ func LogoutHandler() gin.HandlerFunc { sessionstore.RemoveState(fingerPrint) cookie.DeleteSession(gc) - gc.JSON(http.StatusOK, gin.H{ - "message": "Logged out successfully", - }) + if redirectURL != "" { + gc.Redirect(http.StatusPermanentRedirect, redirectURL) + } else { + gc.JSON(http.StatusOK, gin.H{ + "message": "Logged out successfully", + }) + } } }