Skip to content

Commit 60cd317

Browse files
committed
fix: add redirect url to logout
1 parent f5bdc8d commit 60cd317

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

server/handlers/logout.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package handlers
22

33
import (
44
"net/http"
5+
"strings"
56

67
"github.com/authorizerdev/authorizer/server/cookie"
78
"github.com/authorizerdev/authorizer/server/crypto"
@@ -12,6 +13,7 @@ import (
1213
// Handler to logout user
1314
func LogoutHandler() gin.HandlerFunc {
1415
return func(gc *gin.Context) {
16+
redirectURL := strings.TrimSpace(gc.Query("redirect_url"))
1517
// get fingerprint hash
1618
fingerprintHash, err := cookie.GetSession(gc)
1719
if err != nil {
@@ -34,8 +36,12 @@ func LogoutHandler() gin.HandlerFunc {
3436
sessionstore.RemoveState(fingerPrint)
3537
cookie.DeleteSession(gc)
3638

37-
gc.JSON(http.StatusOK, gin.H{
38-
"message": "Logged out successfully",
39-
})
39+
if redirectURL != "" {
40+
gc.Redirect(http.StatusPermanentRedirect, redirectURL)
41+
} else {
42+
gc.JSON(http.StatusOK, gin.H{
43+
"message": "Logged out successfully",
44+
})
45+
}
4046
}
4147
}

0 commit comments

Comments
 (0)