Skip to content

Logging out

Greg Bowler edited this page Nov 1, 2026 · 1 revision

Signing out has two parts: clearing the application's authentication data and visiting the provider to end its session. logout() clears local authentication before redirecting to the provider.

A basic logout endpoint

Inside any wrapped handler:

if (path === '/logout') auth.logout('/signed-out');

The signed-out route should display the result without calling logout() again. Other session data, such as a shopping basket, is preserved.

Choosing the return destination

Destination precedence is:

  1. The explicit argument to logout().
  2. The value configured with setReturnUri().
  3. The provider's deployment default.
auth.setReturnUri('/members/');
auth.logout('/signed-out');

The explicit /signed-out destination wins. With neither setting the provider returns to its configured client URI with do=logout. The local user has already been cleared.

Keep destinations under application control; validate request-supplied routes and origins before using them.

URI objects and query strings

auth.logout(new Uri('https://app.example.com/signed-out'));
// Alternatively: auth.logout(new URL('https://app.example.com/signed-out'));
auth.logout('?signed-out=1');

The query-only form replaces the query on the current request URI. For /account?tab=security, it requests /account?signed-out=1, even if another return URI is configured.

Session state and redirects

The default redirect signal ends execution inside the handler; the adapter sends a 303 after saving. Before redirection, isLoggedIn() is false and getAuthUser() throws NotLoggedInException. Custom redirect handlers must preserve control flow.

Clearing only local data does not clear the provider session. Use logout() to visit the provider too.

Development users

Users with email equal to Authenticator.FAKE_EMAIL are logged out locally without a redirect. A fake user with another email follows ordinary provider logout. See Development and testing.


Continue with Provider links.

Clone this wiki locally