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
What is the right way to do pages structure on site with authorization?
I have a nuxt project with authorization, there is two middlewares auth, no-auth that redirect users to specified pages if they don't have an access to page where this middlewares are included
After that the routes are handled correct, and page /guestPage is the page from /guest/guestPage and doesn't available for registered users, and conversely /userPage is tha page from /user/userPage and doesn't available for guests.
But i feel that i do wrong and there is more easy solution, maybe even "out of the box" that allows to make something like that in automatic way, without adding middleware to each page inside of guest or user directory and extending route to make page /user/userPage.vue be available as /userPage etc.
This question is available on Nuxt.js community (#c2311)
The text was updated successfully, but these errors were encountered:
I think you can add meta: { requiresAuth: true } to your authentication required pages (leave untouched at others) and add a global middleware like below
exportdefaultfunction({ store, route }){constrequiresAuth=route.meta.some(metaData=>metaData.requiresAuth)// check requiresAuth bool and your store (authentication data) and redirect accordingly}
What is the right way to do pages structure on site with authorization?
I have a nuxt project with authorization, there is two middlewares
auth
,no-auth
that redirect users to specified pages if they don't have an access to page where this middlewares are includedI have the following pages directory structure:
In every page in
user
directory there is middlewareauth
andno-auth
in every page inguest
dirSo i added this to my
nuxt.config.js
:After that the routes are handled correct, and page
/guestPage
is the page from/guest/guestPage
and doesn't available for registered users, and conversely/userPage
is tha page from/user/userPage
and doesn't available for guests.But i feel that i do wrong and there is more easy solution, maybe even "out of the box" that allows to make something like that in automatic way, without adding middleware to each page inside of
guest
oruser
directory and extending route to make page/user/userPage.vue
be available as/userPage
etc.The text was updated successfully, but these errors were encountered: