# Handling Invalid State

If you've ever used Socialite in the past, you may be familiar with the `InvalidStateException` you get if you try to refresh the callback route. When you first generate the redirect for a provider, Socialite will generate a random string 40 characters in length and store this in the session. When the user returns and `Socialite::driver(...)->user()` is called, this "pulls" the state stored in the session via `$request->session()->pull()`, and compares this value with a `state` parameter on the callback request.

Socialte will forget the state (remove it from the session) as soon as the value is retrieved from the session (see [here](https://github.com/laravel/framework/blob/a47df681bf4b72cb11e38f7ee7c285406ca934e0/src/Illuminate/Session/Store.php#L306-L309)). As such, subsequent attempts to the callback route will fail. To get around this, you can make both the redirect and callback requests "stateless". However, not all providers support this. You may, therefore, decide to alter this functionality on a per-provider basis. Socialite makes this easy for you, just update`app/Actions/Socialstream/HandleInvalidState.php` with logic specific to your use case.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.socialstream.dev/getting-started/customization/handling-invalid-state.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
