How do I implement logout with Authava?

18 views 1 answers Asked 5/11/2025

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

Anon User 5

asked 5/11/2025

1 Answer

Accepted 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 from localStorage (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

Ryan Hein

answered 5/11/2025

Ask a Question

Your Answer

You need to be logged in to answer this question.

Sign in to Answer