Handle a sign-out route
Server-rendered or Express-style application
Kinde · Module
The TypeScript SDK’s logout method creates a Kinde logout URL from a session manager. Redirect the user to that URL to complete sign-out and return them to the configured post-logout destination.
The TypeScript SDK logout method receives the session manager and returns a logout URL. Redirect the user to that URL so Kinde can end the session and send the user back to a configured allowed logout redirect URL.
kindeClient.logout(sessionManager)| Name | Type | Description |
|---|---|---|
sessionManager | SessionManager | Session manager used by the SDK to access the current authenticated session. |
A logout URL that should be used as the destination of an HTTP redirect.
import { KindeClient } from "@kinde/typescript-sdk";
app.get("/logout", async (req, res) => {
const logoutUrl = await kindeClient.logout(sessionManager);
res.redirect(logoutUrl.toString());
});Create a logout route, generate Kinde's logout URL with the session manager, and redirect the browser to it.
Server-rendered or Express-style application
Navigation-based authentication UI
Applications with a fixed return location
Call kindeClient.logout(sessionManager) from a server route and await the returned URL. Redirect the browser to that URL rather than treating logout as only local session cleanup.
Follow-up: What configuration is needed for the final destination? Register the destination as an Allowed logout redirect URL and configure the SDK’s logout redirect URL accordingly.
logout?The method accepts one argument: a SessionManager. Its result is a URL, which the application should convert to a string and pass to the response redirect.
Follow-up: Why redirect instead of returning the URL as JSON? The browser must navigate to Kinde’s logout endpoint to complete the hosted sign-out flow.
Expose an application route such as /logout, invoke the SDK method there, and redirect to the generated URL. A sign-out link can target that route so the flow runs on the server.
Follow-up: What should be checked if redirecting fails? Verify that the configured post-logout URL exactly matches an allowed logout redirect URL.
SessionManagerlogoutRedirectURLAllowed logout redirect URLs/logout