Skip to content

Commit

Permalink
fix: logout function
Browse files Browse the repository at this point in the history
  • Loading branch information
Björn Urban committed Jul 28, 2024
1 parent a64282f commit 1c91de2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
15 changes: 2 additions & 13 deletions backend/internal/handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,6 @@ func (h *Handler) HandleLogin(w http.ResponseWriter, r *http.Request) {
return
}

token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"user": inputUser.Email,
"exp": time.Now().Add(24 * time.Hour).Unix(),
})

// Sign and get the complete encoded token as a string using the secret
_, err = token.SignedString(h.JWTKey)
if err != nil {
sendJSONError(w, "Internal Server Error", http.StatusInternalServerError)
return
}

session, _ := store.Get(r, "session-cook")
tld, err := extractMainDomain(r.Host)
if err != nil {
Expand Down Expand Up @@ -318,10 +306,11 @@ func (h *Handler) HandleLogout(w http.ResponseWriter, r *http.Request) {

// Clear session values
session.Values["authenticated"] = false
delete(session.Values, "user")

// Expire the cookie
session.Options.MaxAge = -1
tld, err := extractMainDomain(r.Host)
session.Options.Domain = tld

// Save the session
err = session.Save(r, w)
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
{#if $isAuthenticated}
<li class="nav-item">
<Link class="nav-link" to="/requests">Requests</Link>
<button class="nav-link" on:click={logout}>Requests</button>


</li>
<li>
<button class="nav-link" on:click={logout}>Logout</button>
</li>
{/if}
<!-- Add more links as needed -->
</ul>
Expand Down

0 comments on commit 1c91de2

Please sign in to comment.