How do I implement logout with Authava?
What's the recommended way to log out a user using Authava? I want to make sure session cookies are cleared properly.
Anon User 5
asked 5/11/2025
1 Answer
You can log out a user by calling the logout()
method on the AuthavaClient
instance. This clears the session cookie and redirects the user.
await authava.logout("manual"); // optional reason for logout
This will:
- Invalidate the
session cookie
- Broadcast the logout across tabs (if using BroadcastChannel)
- Redirect the user to the login page with a
?next
parameter. - Clear
session_token
fromlocalStorage
(if used)
Make sure your server respects the logout request and clears any associated session state.
โ Option 2: Raw JavaScript (no SDK)
You can also call the logout endpoint directly:
fetch("https://auth.yourdomain.com/logout", {
method: "POST",
credentials: "include", // send http cookies with the request
headers: {
"Accept": "application/json"
}
}).then(() => {
// Optionally redirect to homepage or login
window.location.href = "https://yourapp.com/login"
})
This performs the logout server-side and clears the cookie. You must ensure:
- You're on the same domain or have
SameSite=None; Secure
cookies set - Your browser allows third-party cookies (if logging out from a different domain)
- You handle the redirect after logout
๐ Use this approach if you donโt want to pull in the full Authava client but still need secure session logout.
Best, Ryan Hein Founder
Ryan Hein
answered 5/11/2025
Your Answer
You need to be logged in to answer this question.
Sign in to Answer