Skip to content

Commit

Permalink
fix(backend): update cookie key names
Browse files Browse the repository at this point in the history
  • Loading branch information
Björn Urban committed Oct 16, 2023
1 parent bf1cd0e commit dc98c5a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions backend/internal/handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ func (h *Handler) HandleLogin(w http.ResponseWriter, r *http.Request) {
domain, err := extractMainDomain(r.URL.String())
// Set the token as a cookie
http.SetCookie(w, &http.Cookie{
Name: "auth_token",
Name: "X-Auth-Token",
Value: tokenString,
Expires: time.Now().Add(24 * time.Hour),
HttpOnly: true,
Secure: true, // Set this to true if using HTTPS
Domain: domain, // Adjust to your domain
Secure: true, // Set this to true if using HTTPS
SameSite: http.SameSiteNoneMode, // Set this to true if using HTTPS
Domain: domain, // Adjust to your domain
Path: "/",
})
siteURL, err := h.getRedirectFromCookie(r, w)
Expand Down Expand Up @@ -203,7 +204,7 @@ func (h *Handler) logError(w http.ResponseWriter, message string, err error, sta
}

func (h *Handler) getUserEmailFromToken(r *http.Request) (string, error) {
cookie, err := r.Cookie("auth_token")
cookie, err := r.Cookie("X-Auth-Token")
if err != nil {
return "", fmt.Errorf("Authentication cookie missing")
}
Expand Down Expand Up @@ -235,7 +236,7 @@ func (h *Handler) setRedirectCookie(redirectUrl string, r *http.Request, w http.
}
log.Println(domain)
http.SetCookie(w, &http.Cookie{
Name: "auth-site",
Name: "X-Auth-Site",
Value: redirectUrl,
Expires: time.Now().Add(15 * time.Minute), // Shorter duration
HttpOnly: true,
Expand All @@ -247,7 +248,7 @@ func (h *Handler) setRedirectCookie(redirectUrl string, r *http.Request, w http.
return nil
}
func (h *Handler) getRedirectFromCookie(r *http.Request, w http.ResponseWriter) (string, error) {
cookie, err := r.Cookie("auth-site")
cookie, err := r.Cookie("X-Auth-Site")
if err != nil {
if errors.Is(err, http.ErrNoCookie) {
// No cookie found
Expand Down

0 comments on commit dc98c5a

Please sign in to comment.