Skip to content

Commit

Permalink
(NOBIDS) remember page user tried to access before login (#2973)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelsc authored Nov 6, 2024
1 parent 2054c64 commit 4f2f07e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ func Login(w http.ResponseWriter, r *http.Request) {
RecaptchaKey: utils.Config.Frontend.RecaptchaSiteKey,
}

if redirect := q.Get("redirect"); redirect != "" {
http.SetCookie(w, &http.Cookie{
Name: "redirect-after",
Value: redirect,
MaxAge: 300,
})
} else if redirect := q.Get("redirect_uri"); redirect != "" {
http.SetCookie(w, &http.Cookie{
Name: "redirect-after",
Value: redirect + "&state=" + q.Get("state"),
MaxAge: 300,
})
}

redirectData := struct {
Redirect_uri string
State string
Expand Down Expand Up @@ -339,6 +353,12 @@ func LoginPost(w http.ResponseWriter, r *http.Request) {
return
}

cookie, err := r.Cookie("redirect-after")
if err == nil && cookie.Value != "" {
http.Redirect(w, r, cookie.Value, http.StatusSeeOther)
return
}

// Index(w, r)
http.Redirect(w, r, "/user/notifications", http.StatusSeeOther)
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func UserAuthMiddleware(next http.Handler) http.Handler {
user := getUser(r)
if !user.Authenticated {
utils.SetFlash(w, r, authSessionName, "Error: Please login first")
http.Redirect(w, r, "/login", http.StatusSeeOther)
http.Redirect(w, r, "/login?redirect="+r.URL.Path, http.StatusSeeOther)
return
}
next.ServeHTTP(w, r)
Expand Down

0 comments on commit 4f2f07e

Please sign in to comment.