[**Documentation**](../../../README)

***

[Documentation](../../../README) / [@zerotal/auth](../README) / Guard

# Interface: Guard

Defined in: [auth/src/guards.ts:29](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/auth/src/guards.ts#L29)

The common read surface every guard exposes (all async — guards may do I/O).
The default `web` guard adapts the session-based [Auth](../variables/Auth) facade; named
guards are [RequestGuard](../classes/RequestGuard) instances registered via `Auth.viaRequest`.

## Methods

### user()

> **user**(): `Promise`\<`unknown`\>

Defined in: [auth/src/guards.ts:31](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/auth/src/guards.ts#L31)

The authenticated user; rejects with `UnauthorizedError` when there is none.

#### Returns

`Promise`\<`unknown`\>

***

### userOrNull()

> **userOrNull**(): `Promise`\<`unknown`\>

Defined in: [auth/src/guards.ts:33](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/auth/src/guards.ts#L33)

The authenticated user, or `undefined` when there is none.

#### Returns

`Promise`\<`unknown`\>

***

### id()

> **id**(): `Promise`\<`string` \| `number` \| `undefined`\>

Defined in: [auth/src/guards.ts:35](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/auth/src/guards.ts#L35)

The authenticated user's id, or `undefined` when there is none.

#### Returns

`Promise`\<`string` \| `number` \| `undefined`\>

***

### check()

> **check**(): `Promise`\<`boolean`\>

Defined in: [auth/src/guards.ts:37](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/auth/src/guards.ts#L37)

`true` when a user is authenticated on this guard.

#### Returns

`Promise`\<`boolean`\>

***

### guest()

> **guest**(): `Promise`\<`boolean`\>

Defined in: [auth/src/guards.ts:39](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/auth/src/guards.ts#L39)

`true` when no user is authenticated on this guard.

#### Returns

`Promise`\<`boolean`\>
