You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/2.nuxt-auth/3.application-side/4.protecting-pages.md
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
# Protecting Pages
2
2
3
3
`nuxt-auth` offers different approaches to protect pages:
4
+
4
5
1. Global protection: Protects all pages with manual exceptions
5
6
2. Local protection: Protects specific pages
6
7
3. Custom middleware: Create your own middleware
@@ -48,6 +49,7 @@ That's it! Every page of your application will now need authentication for the u
48
49
### Disabling the global middleware locally
49
50
50
51
To disable the global middleware on a specific page only, you can use the [`definePageMeta` macro](https://nuxt.com/docs/api/utils/define-page-meta#definepagemeta) to turn `auth` off:
52
+
51
53
```vue
52
54
<!-- file: ~/pages/index.vue -->
53
55
<template>
@@ -61,7 +63,6 @@ definePageMeta({ auth: false })
61
63
62
64
Note: This only works on `pages/`. It notably does not work inside the `app.vue`.
63
65
64
-
65
66
## Local middleware
66
67
67
68
To protect specific pages with a middleware, you can use the [`definePageMeta` macro](https://nuxt.com/docs/api/utils/define-page-meta#definepagemeta) to turn `auth` on:
That's it! Every page of your application will now need authentication for the user to visit it.
48
48
49
+
### Middleware Options
50
+
51
+
#### `unauthenticatedOnly`
52
+
53
+
Whether to only allow unauthenticated users to access this page. Authenticated users will be redirected to `/` or the route defined in `navigateAuthenticatedTo`
54
+
55
+
#### `navigateAuthenticatedTo`
56
+
57
+
Where to redirect authenticated users if `unauthenticatedOnly` is set to true
58
+
59
+
#### `navigateUnauthenticatedTo`
60
+
61
+
Where to redirect unauthenticated users if this page is protected
62
+
49
63
### Disabling the global middleware locally
50
64
51
65
To disable the global middleware on a specific page only, you can use the [`definePageMeta` macro](https://nuxt.com/docs/api/utils/define-page-meta#definepagemeta) to turn `auth` off:
0 commit comments