---
url: https://haihv.github.io/valifetch/api/auth.md
---

# valifetch/auth

Built-in `beforeRequest` hook factories for common authentication patterns.

Import from the `valifetch/auth` subpath so the auth code is tree-shaken
out of bundles that don't use it.

## Example

```ts
import valifetch from 'valifetch';
import { bearerAuth, basicAuth, jwtRefresh } from 'valifetch/auth';

const api = valifetch.create({
  hooks: {
    beforeRequest: [bearerAuth(() => localStorage.getItem('token'))],
  },
});
```

## Type Aliases

* [JwtRefreshOptions](type-aliases/JwtRefreshOptions.md)

## Functions

* [basicAuth](functions/basicAuth.md)
* [bearerAuth](functions/bearerAuth.md)
* [jwtRefresh](functions/jwtRefresh.md)
