Skip to content

Commit ecc09ad

Browse files
committed
docs(nuxt): Update route protection
1 parent d3a8a84 commit ecc09ad

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 setup in within the `routeRules` in `nuxt.config.ts`
109+
110+
In the below example,
111+
112+
- `/**` - This protected all routes redirecting the the login route.
113+
- `/dashboard` - route is protected to 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)