> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portalhq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# onSessionInvalidated

> A stream that emits when the backend rejects the Client Auth session Portal was initialized with.

## Function Signature

```dart theme={null}
Stream<void> get onSessionInvalidated
```

## Description

A broadcast stream on `Portal` that emits when the backend rejects the [Client Auth](../guide/client-auth) session `Portal` was initialized with: a `401` on a request that carried the session token, or an MPC operation whose authentication failed. The user has to sign in again.

* It emits at most once per session. Afterwards, `Portal` calls fail with `SESSION_INVALIDATED` until `initialize(session:)` runs with a new session.
* It is not emitted by [`clearSession`](./clearsession), and never for a `Portal` initialized with an API key.
* `Portal()` is a singleton, so the stream carries across `initialize` calls. Subscribe once, before the first `initialize(session:)`. A broadcast stream does not replay, so a listener added after the event never sees it.

The SDK deletes the persisted session when it emits, unless a newer sign-in has already replaced it. Do not call [`clearPersistedSession`](./portalauthclearpersistedsession) in response: it deletes whatever is stored, including that newer session. Still handle errors from the call that failed: the stream tells you the session ended, not which operation failed.

Available starting from `portal_flutter` 2.0.0.

## Parameters

This property takes no parameters.

## Returns

**`Stream<void>`** - Emits once when the session is invalidated.

## Example

```dart theme={null}
import 'package:portal_flutter/portal_flutter.dart';

final subscription = Portal().onSessionInvalidated.listen((_) {
  showSignIn();
});
```

## Errors

This property does not throw.

## Related

* [Handle session invalidation guide](../guide/client-auth#handle-session-invalidation)
* [clearSession](./clearsession)
* [API Keys](../../../resources/api-keys)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.