> ## 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.

# restoreSession

> Get the session persisted on this device, or null when the user is not signed in.

## Function Signature

```dart theme={null}
Future<PortalSession?> restoreSession()
```

## Description

A [`PortalAuth`](./portalauth) method. Returns the session persisted on this device for the configured auth environment, so a returning user does not sign in again. It makes no network call, so a session that has expired is only discovered on its first use, through [`onSessionInvalidated`](./onsessioninvalidated).

`null` means "not signed in", including a stored session the SDK can never read again, which it clears for you.

On iOS, Keychain items survive app deletion, so a reinstalled app can find the previous install's session. See [Start a fresh iOS install from a clean slate](../guide/client-auth#start-a-fresh-ios-install-from-a-clean-slate).

Available starting from `portal_flutter` 2.0.0.

## Parameters

This method takes no parameters.

## Returns

**`PortalSession?`** - The persisted session, or `null` when there is none. Pass it to `Portal().initialize(session:)`.

## Example

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

final session = await PortalAuth().restoreSession();

if (session == null) {
  showSignIn();
} else {
  await Portal().initialize(session: session, rpcConfig: { /* ... */ });
}
```

## Errors

| Code | Description |
| - | - |
| `AUTH_NOT_CONFIGURED` | Called before [`configure`](./portalauthconfigure) |
| `AUTH_SESSION_STORAGE_FAILURE` | Secure storage failed this time. It may succeed on the next attempt |
| `AUTH_RESTORE_SESSION_ERROR` | Any other failure |

## Related

* [Restore the session on launch guide](../guide/client-auth#restore-the-session-on-launch)
* [clearPersistedSession](./portalauthclearpersistedsession)
* [onSessionInvalidated](./onsessioninvalidated)


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