elegant-plumber-79804
12/23/2025, 6:31 PMchilly-king-10285
12/23/2025, 6:31 PMchilly-king-10285
12/23/2025, 6:31 PMts // /logout route app.get("/logout", async (req, res) => { try { const { logout_url } = await ory.createBrowserLogoutFlow({ cookie: req.header("cookie"), }) res.redirect(logout_url) } catch (err) { res.redirect("/") } }) Under the hood this calls: - GET /self-service/logout/browser to create the logout URL [[createBrowserLogoutFlow](https://www.ory.sh/docs/reference/api)] - Then the browser follows that URL, which hits GET /self-service/logout to complete logout [[updateLogoutFlow](https://www.ory.sh/docs/reference/api)] After successful logout, Ory: - Invalidates the session - Removes the session cookie - Redirects to return_to or the configured default post‑logout URL [[Sign out](https://www.ory.com/docs/identities/get-started/sign-out); [Logout flow](https://www.ory.com/docs/kratos/self-service/flows/user-logout)] --- ### 2. SPA (single‑page application) Flow: 1. Call createBrowserLogoutFlow from the browser (with credentials). 2. Call updateLogoutFlow with the returned logout_token. Example (React): [[SPA logout](https://www.ory.com/docs/kratos/self-service/flows/user-logout#single-page-application-spa)] ts import { Configuration, FrontendApi } from "@ory/client" const frontend = new FrontendApi( new Configuration({ basePath: "<http://localhost:4000>", // Ory Tunnel / project URL baseOptions: { withCredentials: true }, }), ) export function Logout() { const handleLogout = async () => { try { const { data: flow } = await frontend.createBrowserLogoutFlow() await frontend.updateLogoutFlow({ token: flow.logout_token }) } catch (error) { // handle error } } return <button onClick={handleLogout}>Logout</button> } --- ### 3. Native / API clients (mobile, backend using session tokens) Use the native logout endpoint directly with the session token: - DELETE /self-service/logout/api with JSON body { "session_token": "<token>" } [[performNativeLogout](https://www.ory.sh/docs/reference/api); [Native logout](https://www.ory.com/docs/kratos/self-service/flows/user-logout#native-api-applications)] TypeScript example: ts import { Configuration, FrontendApi } from "@ory/client" const frontend = new FrontendApi( new Configuration({ basePath: `https://${process.env.ORY_PROJECT_SLUG}.<http://projects.oryapis.com|projects.oryapis.com>`, }), ) export async function logout(token: string) { return await frontend.performNativeLogout({ performNativeLogoutBody: { session_token: token, }, }) } This revokes the session token but does not touch browser cookies (so it’s for non‑browser/native use). [[performNativeLogout](https://www.ory.sh/docs/reference/api)] --- If you tell me your app type (SSR, SPA, mobile, etc.), I can point you to the exact pattern you should use.elegant-plumber-79804
12/23/2025, 6:34 PMchilly-king-10285
12/23/2025, 6:34 PMchilly-king-10285
12/23/2025, 6:34 PMlogout_token and logout_url). 2. Complete the logout by calling the logout URL (or /self-service/logout?token=...). 3. Use credentials: "include" so cookies (session, CSRF) are sent. [[Logout flow](https://www.ory.com/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#logout-flow); [SPA flows](https://www.ory.com/docs/kratos/self-service#browser-flows-for-client-side-apps-single-page-apps-reactjs-angular-nextjs-)] ### 1. Create logout flow js // Step 1: Get logout_url and logout_token const res = await fetch( "https://$<http://PROJECT_SLUG.projects.oryapis.com/self-service/logout/browser|PROJECT_SLUG.projects.oryapis.com/self-service/logout/browser>", { method: "GET", headers: { "Accept": "application/json", }, credentials: "include", // important for cookies }, ) if (!res.ok) { // handle error (e.g. user not logged in) } const flow = await res.json() // flow.logout_url // flow.logout_token This corresponds to GET /self-service/logout/browser and returns JSON like: [[Logout flow](https://www.ory.com/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#logout-flow)] json { "logout_url": "https://$<http://PROJECT_SLUG.projects.oryapis.com/self-service/logout?token=J6yIQf7ABx1BBiPOj036dJKSQmKwGnX6|PROJECT_SLUG.projects.oryapis.com/self-service/logout?token=J6yIQf7ABx1BBiPOj036dJKSQmKwGnX6>", "logout_token": "J6yIQf7ABx1BBiPOj036dJKSQmKwGnX6" } ### 2. Complete logout (AJAX style) Instead of redirecting, call the logout URL via `fetch`: js // Step 2: Call the logout URL (or build it from the token) await fetch(flow.logout_url, { method: "GET", headers: { "Accept": "application/json", }, credentials: "include", }) // On success, Ory invalidates the session and clears the cookie. // If Accept != application/json, this would be a 303 redirect instead. This hits GET /self-service/logout?token=... (the updateLogoutFlow endpoint). [[Logout flow](https://www.ory.com/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#logout-flow); [updateLogoutFlow](https://www.ory.sh/docs/reference/api)] That’s all you need for SPA logout without the SDK: two fetch calls with credentials: "include".elegant-plumber-79804
12/23/2025, 6:40 PMchilly-king-10285
12/23/2025, 6:40 PMchilly-king-10285
12/23/2025, 6:40 PMdisableMySession [[Revoke specific session](https://www.ory.com/docs/kratos/session-management/list-revoke-get-sessions#revoking-a-specific-session)] - Revoke all other sessions: disableMyOtherSessions [[Revoke all other sessions](https://www.ory.com/docs/kratos/session-management/list-revoke-get-sessions#revoking-all-other-sessions)] If you want “log out from everywhere” behavior, you need to call those revoke-session APIs (or use the revoke_active_sessions Action hook on login) in addition to the normal self-service logout. [[One active session](https://www.ory.com/docs/actions/revoke-active-sessions)]