Ask AI is now on the home page — ask a question and get a sourced answer from the Ory docs. You'll also find it in the bottom-right corner of any page.

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