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 dc98c5a commit 4320420
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions backend/internal/handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ func (h *Handler) HandleLogin(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
domain, err := extractMainDomain(r.URL.String())
siteURL, err := h.getRedirectFromCookie(r, w)
if err != nil {
http.Error(w, "Redirect URL missing", http.StatusBadRequest)
return
}
if siteURL == "" {
siteURL = r.Host
}
domain, err := extractMainDomain(siteURL)
// Set the token as a cookie
http.SetCookie(w, &http.Cookie{
Name: "X-Auth-Token",
Expand All @@ -89,13 +97,7 @@ func (h *Handler) HandleLogin(w http.ResponseWriter, r *http.Request) {
Domain: domain, // Adjust to your domain
Path: "/",
})
siteURL, err := h.getRedirectFromCookie(r, w)
if siteURL == "" {
http.Error(w, "Redirect URL missing", http.StatusBadRequest)
return
} else {
http.Redirect(w, r, siteURL, http.StatusSeeOther)
}
http.Redirect(w, r, siteURL, http.StatusSeeOther)
// Here, you'd typically generate a JWT or session token and send it back to the client.
// For simplicity, we'll just send a success message.
_, err = w.Write([]byte("Login successful"))
Expand Down

0 comments on commit 4320420

Please sign in to comment.