Unable to restrict /es/admin path
I am using i18n Nuxt extension.
This is my code:
I can visit /admin and cannot visit /es/admin . That's great and as expected.
But I can visti both /admin/settings and /es/admin/settings. Which is not good.
How to use stars or regex or something to block every other subpath for /es locale/prefix?
3 Replies
Hi @Wirkhof. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided in the knowledge sources, I can offer some insights into your issue with restricting the
/es/admin
path using the Nuxt i18n module.
The configuration you've shown is close, but there's a small adjustment needed to achieve what you're trying to do. According to the Nuxt i18n documentation (https://nuxt.com/docs/getting-started/configuration), the pages
configuration in the i18n module is used to define custom routes for specific pages, not to restrict access to certain paths.
To restrict access to the /es/admin
path, you should use the routeRules
configuration in your nuxt.config.ts
file instead. Here's how you can modify your configuration:
In this configuration, we've moved the admin route rules to the routeRules
section. The '**'
wildcard will match all paths under /es/admin/
and /admin/
, effectively applying the rule to all admin pages in both languages.
The { ssr: false }
setting will make these routes client-side only, which can be a way to restrict access. However, if you want to completely block access to these routes, you might need to implement additional logic in your middleware or server-side code.
Remember that this configuration will affect how these routes are rendered and accessed, but it doesn't provide authentication or authorization by itself. For proper access control, you should implement authentication and authorization logic in your application.
Nuxt Configuration Reference (https://nuxt.com/docs/getting-started/configuration) provides more details on how to use routeRules
and other configuration options in Nuxt 3.
If this doesn't solve your specific issue, you might need to provide more details about what exactly you're trying to achieve with the /es/admin
path restriction.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1184447325335199871> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Not gonna lie, if page is localized I prefere to use prefix on all pages, or no prefix at all. It's going to work any way correct cause i18n redirect on default browser locale if enabled.
You have literary described here how to do it.
https://i18n.nuxtjs.org/docs/v8/guide/custom-paths#module-configuration