Skip to content

Commit

Permalink
Fix redirect links when session errors (#681)
Browse files Browse the repository at this point in the history
* fix redirect links when session errors

* fix set roles bug
  • Loading branch information
zhendi authored Sep 26, 2024
1 parent 34861d6 commit 8e2fe44
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/handlers/render/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (i *SessionHandlerImpl) Create(ctx *gin.Context) {
jwtToken := ctx.Query("jwt")
if jwtToken == "" {
slog.Error("Login Error", "error", "jwt is blank")
ctx.Redirect(http.StatusFound, "/error/login-failed?error_msg='invalid jwt token'")
ctx.Redirect(http.StatusFound, "/errors/login-failed?error_msg='invalid jwt token'")
return
}
userResp, _, err := i.Server.VerifyJWTToken(jwtToken)
Expand All @@ -70,7 +70,7 @@ func (i *SessionHandlerImpl) Create(ctx *gin.Context) {

if userResp == nil {
slog.Error("Login Error", "error", "verify jwt token failed", "jwt", jwtToken)
ctx.Redirect(http.StatusFound, "/error/login-failed?error_msg='invalid jwt token'")
ctx.Redirect(http.StatusFound, "/errors/login-failed?error_msg='invalid jwt token'")
return
}

Expand All @@ -89,8 +89,6 @@ func (i *SessionHandlerImpl) Create(ctx *gin.Context) {
LoginIdentity: userResp.UUID,
}

user.SetRoles(userResp.Roles...)

err = i.userModel.Create(ctx, user)
if err != nil {
stackTrace := string(debug.Stack())
Expand All @@ -99,11 +97,13 @@ func (i *SessionHandlerImpl) Create(ctx *gin.Context) {
return
}
} else {
ctx.Redirect(http.StatusFound, "/error/login-failed?error_msg='invalid jwt token'")
ctx.Redirect(http.StatusFound, "/errors/login-failed?error_msg='invalid jwt token'")
return
}
}

user.SetRoles(userResp.Roles...)

ctx.SetCookie("login_identity", user.LoginIdentity, cookieMaxAge, "/", "", false, false)
ctx.SetCookie("current_user", user.Name, cookieMaxAge, "/", "", false, false)
ctx.SetCookie("admin_user", fmt.Sprintf("%t", user.IsAdmin()), cookieMaxAge, "/", "", false, false)
Expand Down

0 comments on commit 8e2fe44

Please sign in to comment.