Skip to main content

Implementing user logout

The logout flow allows users to securely terminate their sessions. This guide shows how to implement proper logout functionality in your application.

// Create logout route
app.get("/logout", async (req, res) => {
try {
// Create a logout flow
const { logout_url } = await ory.createBrowserLogoutFlow({
cookie: req.header("cookie"),
})
// Redirect to logout URL
res.redirect(logout_url)
} catch (err) {
res.redirect("/")
}
})

After successful logout

Ory:

  1. Invalidates the user's session
  2. Removes the session cookie from the browser
  3. Redirects the user to the specified return URL