refactor: fall back and check for DEFAULT_AUTH_COOKIE_NAME

This commit is contained in:
Derrick Hammer 2024-03-17 08:13:50 -04:00
parent 193871f083
commit b03e6815e2
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 5 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import (
) )
const DEFAULT_AUTH_CONTEXT_KEY = "user_id" const DEFAULT_AUTH_CONTEXT_KEY = "user_id"
const DEFAULT_AUTH_COOKIE_NAME = "auth_token"
type JapeMiddlewareFunc func(jape.Handler) jape.Handler type JapeMiddlewareFunc func(jape.Handler) jape.Handler
type HttpMiddlewareFunc func(http.Handler) http.Handler type HttpMiddlewareFunc func(http.Handler) http.Handler
@ -75,6 +76,10 @@ func FindAuthToken(r *http.Request, cookieName string, queryParam string) string
return cookie.Value return cookie.Value
} }
if cookie, err := r.Cookie(DEFAULT_AUTH_COOKIE_NAME); cookie != nil && err == nil {
return cookie.Value
}
return r.FormValue(queryParam) return r.FormValue(queryParam)
} }