New Ory Agent Security is now live! Claim your complimentary test drive. Get Started!

Skip to main content

Sign out

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
export const registerLogoutRoute = (app, ory) => {
app.get("/logout", async (req, res) => {
try {
// Create a logout flow
const { data } = await ory.createBrowserLogoutFlow({
cookie: req.header("cookie"),
})
const logoutUrl = data.logout_url || data.logoutUrl
// Redirect to logout URL
res.redirect(logoutUrl)
} catch (err) {
res.redirect("/")
}
})
}

After successful logout​

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