# MoveAuthState

Returns the current SDK Authentication State.

{% tabs %}
{% tab title="Android" %}

```kotlin
enum class MoveAuthState {
    UNKNOWN,
    VALID(MoveAuth)
    EXPIRED(MoveAuth)
}
```

{% endtab %}

{% tab title="iOS" %}

```swift
enum MoveAuthState {
    case unknown
    case expired
    case valid(MoveAuth)
}
```

{% endtab %}

{% tab title="React Native" %}

```javascript
export type AuthState = 'unknown' | 'valid' | 'expired';
```

{% endtab %}
{% endtabs %}

| MoveAuthState                                                                                |                                                                                                                                  |
| -------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| expired([MoveAuth](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth)) | Latest [MoveAuth](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth) expired and the SDK can't refresh it. |
| valid([MoveAuth](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth))   | Authentication is valid. Latest [MoveAuth](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth) provided.    |
| unknown                                                                                      | The SDK authorization state when SDK is uninitialized.                                                                           |

### Authentication updates and expiry

[MoveAuth](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth) is session-based, hence it expires and requires to be renewed. For simplicity, the MOVE SDK handles refreshing the token for the host app whenever it expires and passes the new MoveAuth when updated via `authStateChangeListener` (Android / [iOS](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/ios/services#set-sdk-auth-state-listener)) API callback.

In case the SDK fails to refresh authentication, it will trigger [MoveAuthState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauthstate)`.expired`. The host app is expected to fetch a new token with the product's API Key and then call `update(auth: MoveAuth)`([Android](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/android-1/android#update-authentication) / [iOS](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/ios/services#update-authentication)) API.

{% hint style="warning" %}

#### Authentication Updates

The host app is responsible for monitoring [MoveAuthState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauthstate) updates and handling its state updates by:

* `.expired`: Requesting new Auth using the product's API Key and then passing it to the SDK using [`update(auth: MoveAuth)`](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/ios/services#update-authentication) API.
* `.valid(MoveAuth)`: Persisting the new [MoveAuth](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth) provided by the SDK, so the app can pass this new [MoveAuth](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth) next time it is initializing the SDK.
  {% endhint %}

| MoveAuthState related APIs                                                                                                                              |                                                                                                                                       |
| ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `getSDKAuthState` (Android / [iOS](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/ios/services#get-sdk-auth-state))                  | Gets the current [MoveAuthState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauth).                            |
| setSDKAuthUpdatesListener (Android / [iOS](https://docs.movesdk.com/move-platform/move-sdk-1.x/api-interface/ios/services#set-sdk-auth-state-listener)) | Block to be invoked every time [MoveAuthState](https://docs.movesdk.com/move-platform/move-sdk-1.x/sdk/models/moveauthstate) changes. |
