# AuthenticationManager

Defined in: [react/src/auth/authentication-manager.ts:62](https://github.com/B3Pay/ic-reactor/blob/70bedf3c8779611a3b35710510442dee7f630b87/packages/react/src/auth/authentication-manager.ts#L62)

Manages Internet Identity sign-in, session restoration, and authentication
state for a [ClientManager](https://ic-reactor.b3pay.net/v3/libs/classes/clientmanager/).

## Example

```ts
const authentication = new AuthenticationManager({ clientManager })
const identity = await authentication.authenticate()
```

## Constructors

### Constructor

> **new AuthenticationManager**(`__namedParameters`): `AuthenticationManager`

Defined in: [react/src/auth/authentication-manager.ts:102](https://github.com/B3Pay/ic-reactor/blob/70bedf3c8779611a3b35710510442dee7f630b87/packages/react/src/auth/authentication-manager.ts#L102)

#### Parameters

##### \_\_namedParameters

[`AuthenticationManagerParameters`](https://ic-reactor.b3pay.net/v3/libs/interfaces/authenticationmanagerparameters/)

#### Returns

`AuthenticationManager`

## Properties

### clientManager

> `readonly` **clientManager**: [`ClientManager`](https://ic-reactor.b3pay.net/v3/libs/classes/clientmanager/)

Defined in: [react/src/auth/authentication-manager.ts:95](https://github.com/B3Pay/ic-reactor/blob/70bedf3c8779611a3b35710510442dee7f630b87/packages/react/src/auth/authentication-manager.ts#L95)

## Accessors

### authState

#### Get Signature

> **get** **authState**(): [`AuthState`](https://ic-reactor.b3pay.net/v3/libs/interfaces/authstate/)

Defined in: [react/src/auth/authentication-manager.ts:98](https://github.com/B3Pay/ic-reactor/blob/70bedf3c8779611a3b35710510442dee7f630b87/packages/react/src/auth/authentication-manager.ts#L98)

The current authentication state.

##### Returns

[`AuthState`](https://ic-reactor.b3pay.net/v3/libs/interfaces/authstate/)

## Methods

### subscribeAuthState()

> **subscribeAuthState**(`callback`): () => `void`

Defined in: [react/src/auth/authentication-manager.ts:158](https://github.com/B3Pay/ic-reactor/blob/70bedf3c8779611a3b35710510442dee7f630b87/packages/react/src/auth/authentication-manager.ts#L158)

#### Parameters

##### callback

(`state`) => `void`

#### Returns

() => `void`

***

### prepareClient()

> **prepareClient**(`options?`): `Promise`\<[`AuthClientLike`](https://ic-reactor.b3pay.net/v3/libs/interfaces/authclientlike/) \| `undefined`\>

Defined in: [react/src/auth/authentication-manager.ts:175](https://github.com/B3Pay/ic-reactor/blob/70bedf3c8779611a3b35710510442dee7f630b87/packages/react/src/auth/authentication-manager.ts#L175)

Preloads the auth module and creates an AuthClient ahead of time.

Call (and await) this before wiring up a login button: it makes
[login](#login) and [IdentityAttributesManager.request](https://ic-reactor.b3pay.net/v3/libs/classes/identityattributesmanager/#request) able to open
the identity provider synchronously inside the click handler, which is
what browser popup blockers and the ICRC-29 transport require.

#### Parameters

##### options?

[`AuthenticationClientOptions`](https://ic-reactor.b3pay.net/v3/libs/interfaces/authenticationclientoptions/)

#### Returns

`Promise`\<[`AuthClientLike`](https://ic-reactor.b3pay.net/v3/libs/interfaces/authclientlike/) \| `undefined`\>

***

### getPreparedClient()

> **getPreparedClient**(`options?`): [`AuthClientLike`](https://ic-reactor.b3pay.net/v3/libs/interfaces/authclientlike/) \| `undefined`

Defined in: [react/src/auth/authentication-manager.ts:232](https://github.com/B3Pay/ic-reactor/blob/70bedf3c8779611a3b35710510442dee7f630b87/packages/react/src/auth/authentication-manager.ts#L232)

Returns an AuthClient without awaiting, or `undefined` when the auth
module has not been loaded yet.

Callers that must stay inside a user gesture use this instead of
`ensureClient`; awaiting anything before opening the identity
provider window loses the gesture.

#### Parameters

##### options?

[`AuthenticationClientOptions`](https://ic-reactor.b3pay.net/v3/libs/interfaces/authenticationclientoptions/)

#### Returns

[`AuthClientLike`](https://ic-reactor.b3pay.net/v3/libs/interfaces/authclientlike/) \| `undefined`

***

### authenticate()

> **authenticate**(): `Promise`\<`Identity` \| `undefined`\>

Defined in: [react/src/auth/authentication-manager.ts:238](https://github.com/B3Pay/ic-reactor/blob/70bedf3c8779611a3b35710510442dee7f630b87/packages/react/src/auth/authentication-manager.ts#L238)

#### Returns

`Promise`\<`Identity` \| `undefined`\>

***

### login()

> **login**(`loginOptions?`): `Promise`\<`void`\>

Defined in: [react/src/auth/authentication-manager.ts:341](https://github.com/B3Pay/ic-reactor/blob/70bedf3c8779611a3b35710510442dee7f630b87/packages/react/src/auth/authentication-manager.ts#L341)

#### Parameters

##### loginOptions?

[`AuthenticationSignInOptions`](https://ic-reactor.b3pay.net/v3/libs/interfaces/authenticationsigninoptions/)

#### Returns

`Promise`\<`void`\>

***

### logout()

> **logout**(`options?`): `Promise`\<`void`\>

Defined in: [react/src/auth/authentication-manager.ts:399](https://github.com/B3Pay/ic-reactor/blob/70bedf3c8779611a3b35710510442dee7f630b87/packages/react/src/auth/authentication-manager.ts#L399)

#### Parameters

##### options?

###### returnTo?

`string`

#### Returns

`Promise`\<`void`\>