# RevolutId interface

RevolutId is main SDK interface returned by `RevolutIdLoader` for authentication management.

## Methods

### `initialise(config: Config)`

Initialises the authentication client with your configuration.

**Parameters:** `config: Config` - client configuration parameters

**Returns:** `{ mountButton: (container: HTMLElement, params?: ButtonStyle) => ButtonClient }` - object with mountButton method

### `processRedirectParams()`

Processes URL parameters after redirect to extract authorization result.

**Returns:** `SuccessResult | ErrorResult | null`

## Config parameters

Configuration parameters for initializing the Revolut ID authentication client using discriminated union types.

### Type definition

```typescript
type BaseConfig = {
  clientId: string
  redirectUri: string
  scope: OpenIdScope[]
  colorScheme?: ColorScheme
  countryCodes?: string[]
  locale?: string
  mode?: Mode
}

type PopupClientConfig = BaseConfig & {
  displayMode: 'popup'
  onAuthSuccess: (result: SuccessResult) => void
  onAuthFailure?: (result: ErrorResult) => void
}

type RedirectClientConfig = BaseConfig & {
  displayMode?: 'redirect'
}

export type Config = PopupClientConfig | RedirectClientConfig
```

### Parameters

| Parameter       | Type                                         | Description                             | Default                 | Required              |
| --------------- | -------------------------------------------- | --------------------------------------- | ----------------------- | --------------------- |
| `clientId`      | <code>string</code>                          | Your Revolut application client ID      | -                       | Yes                   |
| `redirectUri`   | <code>string</code>                          | URI to redirect to after authentication | -                       | Yes                   |
| `scope`         | <code>OpenIdScope[]</code>                   | Array of requested OpenID scopes        | -                       | Yes                   |
| `displayMode`   | <code>popup \| redirect</code>               | Authentication flow mode                | <code>redirect</code>   | No                    |
| `onAuthSuccess` | <code>(result: SuccessResult) => void</code> | Success callback function               | -                       | Yes (popup mode only) |
| `onAuthFailure` | <code>(result: ErrorResult) => void</code>   | Error callback function                 | -                       | No (popup mode only)  |
| `mode`          | <code>production \| sandbox</code>           | Environment mode                        | <code>production</code> | No                    |
| `colorScheme`   | <code>light \| dark \| auto</code>           | UI theme preference                     | -                       | No                    |
| `countryCodes`  | <code>string[]</code>                        | Array of allowed country codes          | -                       | No                    |
| `locale`        | <code>string</code>                          | Language/locale code                    | -                       | No                    |

### Available scopes

| Scope         | Description                                    |
| ------------- | ---------------------------------------------- |
| `openid`      | Required - Basic OpenID Connect authentication |
| `profile`     | User's basic profile information               |
| `name`        | User's full name                               |
| `email`       | User's email address                           |
| `phone`       | User's phone number                            |
| `address`     | User's address information                     |
| `birthdate`   | User's date of birth                           |
| `citizenship` | User's verified citizenship                    |

### Supported locales

`bg`, `cs`, `da`, `de`, `el`, `en`, `en_US`, `es`, `es_MX`, `fi`, `fr`, `hr`, `hu`, `it`, `ja`, `lt`, `lv`, `nb`, `nl`, `pl`, `pt`, `pt_BR`, `ro`, `ru`, `sk`, `sv`, `uk`

## Result types

### SuccessResult

Returned when authentication completes successfully.

```typescript
type SuccessResult = {
  status: 'success'
  code: string
  codeVerifier: string
}
```

| Property       | Type                 | Description                         |
| -------------- | -------------------- | ----------------------------------- |
| `status`       | <code>success</code> | Indicates successful authentication |
| `code`         | <code>string</code>  | Authorization code from Revolut     |
| `codeVerifier` | <code>string</code>  | PKCE verification string            |

### ErrorResult

Returned when authentication fails or is cancelled.

```typescript
type ErrorResult = {
  status: 'error'
  error: ErrorType
  errorDescription?: string
}
```

| Property           | Type                   | Description                      |
| ------------------ | ---------------------- | -------------------------------- |
| `status`           | <code>error</code>     | Indicates authentication failure |
| `error`            | <code>ErrorType</code> | Specific error code              |
| `errorDescription` | <code>string</code>    | Optional error description       |

#### Error types

| Error Code                   | Description                        |
| ---------------------------- | ---------------------------------- |
| `registration_not_supported` | Registration flow not supported    |
| `user_cancelled`             | User cancelled authentication      |
| `access_denied`              | Access denied by user              |
| `authorise_declined`         | Authorization declined             |
| `unknown`                    | Unknown error occurred             |
| `timeout`                    | Authentication timed out           |
| `interrupted`                | Authentication flow interrupted    |
| `popup_blocked`              | Popup was blocked by browser       |
| `popup_closed`               | Popup was closed before completion |
| `iframe_failed`              | iFrame authentication failed       |
| `code_verifier_not_found`    | PKCE code verifier not found       |
| `code_verifier_already_used` | PKCE code verifier already used    |
| `state_not_found`            | OAuth state parameter not found    |