mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
fix(auth): invalid session error (#892)
* chore: ignore dist dir * fix(auth): speculative invalid session
This commit is contained in:
parent
61439567d8
commit
83e9232b98
2 changed files with 10 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -39,3 +39,4 @@ tmp/
|
||||||
package-lock.json
|
package-lock.json
|
||||||
# Ditto for yarn, except we're using npm.
|
# Ditto for yarn, except we're using npm.
|
||||||
yarn.lock
|
yarn.lock
|
||||||
|
dist/
|
||||||
|
|
|
@ -108,6 +108,7 @@ func (h authHandler) logout(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Revoke users authentication
|
// Revoke users authentication
|
||||||
session.Values["authenticated"] = false
|
session.Values["authenticated"] = false
|
||||||
|
session.Options.MaxAge = -1
|
||||||
if err := session.Save(r, w); err != nil {
|
if err := session.Save(r, w); err != nil {
|
||||||
h.encoder.StatusError(w, http.StatusInternalServerError, errors.Wrap(err, "could not save session"))
|
h.encoder.StatusError(w, http.StatusInternalServerError, errors.Wrap(err, "could not save session"))
|
||||||
return
|
return
|
||||||
|
@ -119,16 +120,15 @@ func (h authHandler) logout(w http.ResponseWriter, r *http.Request) {
|
||||||
func (h authHandler) onboard(w http.ResponseWriter, r *http.Request) {
|
func (h authHandler) onboard(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|
||||||
session, err := h.cookieStore.Get(r, "user_session")
|
session, _ := h.cookieStore.Get(r, "user_session")
|
||||||
if err != nil {
|
|
||||||
h.log.Error().Err(err).Msg("could not get session")
|
|
||||||
h.encoder.StatusError(w, http.StatusInternalServerError, errors.New("could not get session"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't proceed if user is authenticated
|
// Don't proceed if user is authenticated
|
||||||
if authenticated, ok := session.Values["authenticated"].(bool); ok {
|
if authenticated, ok := session.Values["authenticated"].(bool); ok {
|
||||||
if ok && authenticated {
|
if ok && authenticated {
|
||||||
|
session.Values["authenticated"] = false
|
||||||
|
session.Options.MaxAge = -1
|
||||||
|
session.Save(r, w)
|
||||||
|
|
||||||
h.encoder.StatusError(w, http.StatusForbidden, errors.New("active session found"))
|
h.encoder.StatusError(w, http.StatusForbidden, errors.New("active session found"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -177,6 +177,9 @@ func (h authHandler) validate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Check if user is authenticated
|
// Check if user is authenticated
|
||||||
if auth, ok := session.Values["authenticated"].(bool); !ok || !auth {
|
if auth, ok := session.Values["authenticated"].(bool); !ok || !auth {
|
||||||
|
session.Values["authenticated"] = false
|
||||||
|
session.Options.MaxAge = -1
|
||||||
|
session.Save(r, w)
|
||||||
h.encoder.StatusError(w, http.StatusUnauthorized, errors.New("forbidden: invalid session"))
|
h.encoder.StatusError(w, http.StatusUnauthorized, errors.New("forbidden: invalid session"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue