> For the complete documentation index, see [llms.txt](https://nuxt-community.gitbook.io/auth/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nuxt-community.gitbook.io/auth/docs/guide/middleware.md).

# Middleware

You can enable `auth` middleware either globally or per route. When this middleware is enabled on a route and `loggedIn` is `false` user will be redirected to `redirect.login` route. (`/login` by default)

Setting per route:

```javascript
export default {
  middleware: 'auth'
}
```

Globally setting in `nuxt.config.js`:

```javascript
router: {
  middleware: ['auth']
}
```

In case of global usage, You can set `auth` option to `false` in a specific component and the middleware will ignore that route.

```javascript
export default {
  auth: false
}
```

You can set `auth` option to `guest` in a specific component. When this middleware is enabled on a route and `loggedIn` is `true` user will be redirected to `redirect.home` route. (`/` by default)

```javascript
export default {
  auth: 'guest'
}
```
