Skip to content

Commit 41b17de

Browse files
Merge pull request #382 from kinde-oss/docs/nuxt/update-route-protection
docs(nuxt): Update route protection
2 parents 4b280f1 + 066aad5 commit 41b17de

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

src/content/docs/developer-tools/sdks/backend/nuxt-module.mdx

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,43 @@ NUXT_KINDE_POST_LOGIN_REDIRECT_URL=<where_your_project_is_running>
103103

104104
## Protecting pages
105105

106-
It’s likely that your project will have both pages that are publicly available and private ones which should only be available to logged in users. Add this code snippet to pages you would like to protect.
106+
It’s likely that your project will have both pages that are publicly available and private ones which should only be available to logged in users.
107+
108+
Route protection is set up in within the `routeRules` in `nuxt.config.ts`
109+
110+
In the below example,
111+
112+
- `/**` - This protected all routes redirecting the login route.
113+
- `/dashboard` - route is protected for users with `admin` permissions.
114+
- `/public` - this is flagged as a public route and will be open to all visitors.
107115

108116
```jsx
109-
<script setup lang="ts">
110-
definePageMeta({
111-
middleware: ['auth-logged-in'],
112-
})
113-
</script>
117+
routeRules: {
118+
'/**': {
119+
appMiddleware: ['auth-logged-in'],
120+
kinde: {
121+
redirectUrl: '/api/login',
122+
external: true,
123+
},
124+
},
125+
'/dashboard': {
126+
appMiddleware: ['auth-logged-in'],
127+
kinde: {
128+
// list of permissions that are required to access the route
129+
permissions: {
130+
admin: true,
131+
},
132+
redirectUrl: '/api/login',
133+
external: true,
134+
},
135+
},
136+
'/public': {
137+
appMiddleware: ['auth-logged-in'],
138+
kinde: {
139+
public: true,
140+
},
141+
},
142+
},
114143
```
115144

116145
## Getting all permissions for the current user

0 commit comments

Comments
 (0)