sexyGaming - Kiroma
sexyGaming - Kiroma
NNuxt
Created by lav on 8/1/2024 in #❓・help
Middleare for Auth
But to answer your specific problem, as your stack blitz was a bit too minimal, this is what you want to achieve? https://stackblitz.com/edit/github-rwecso-79iacs?file=pages%2Findex.vue
21 replies
NNuxt
Created by lav on 8/1/2024 in #❓・help
Middleare for Auth
Never trust the user controled data, esp. in such cases as if he is logged in and as whom he is logged in. So local storage can be tampered with and then the user is logged in because someone set a value to true and/or changed the userid in there and now impersonated it. (Okay if you have session management then this may be a bit exaggerated because you would need to know the session but the point stands) So yes you also have to check it server side when he initially comes and redirect him away. If the session timed out in the client then you need to also handle that in a middleware. Multiple ways you can go there. Either force reload and let the server handle the redirect or implement the logic you have written there. Your middleware for protected pages should only be triggered on protected pages. Register and Login, or the landingpage, would not have the authentication middleware or, as another user already stated, you could disable that via custom page meta. Thus you would not need to check the current path. If it is global and you don't use a custom property to disable it, then you will need to do the routes checking from your example.
21 replies
NNuxt
Created by ægteemil on 8/4/2024 in #❓・help
Strongly typed i18n
You could always provide that by indirection (having an object containing your root translation as plain js/ts object which you then include in your components (or auti-import) and add into the i18n module as your value object). But maybe this https://github.com/nuxt-modules/i18n/issues/1753 woudl also already alleviate all your problems when it someday gets implemented?
2 replies
NNuxt
Created by abd on 8/4/2024 in #❓・help
useFetch && $fetch
If its used both on server and client you can always use both by doing an if(import.meta.client) or if(import.meta.server) and thus do a useFetch or $fetch. But maybe I am exeggarting the problem because I myself did not 100% understood how to use the fetching in gerneral correctly 😄
6 replies
NNuxt
Created by abd on 8/4/2024 in #❓・help
useFetch && $fetch
Also in terms of SSR its a good idea to use useAsyncData because it will not lead to 2 requests, as it will get hydrated into the client instead of having both to call it initially.
6 replies
NNuxt
Created by abd on 8/4/2024 in #❓・help
useFetch && $fetch
Just in case you have an authentication system and now use $fetch and sometimes see an unauthenticated user in your logs even though you are logged in, thats why I mention it... SPent a while on figuring that out last time, saving you the trouble.
6 replies
NNuxt
Created by abd on 8/4/2024 in #❓・help
useFetch && $fetch
As far as I understood it: useFetch for everything on the server and $fetch for everything a user action may trigger. But I think you can use the refresh nad/or execute method you get from the useFetch in the client side code to also refetch. Fun part is also, that you can use $fetch on server side but it will not send your whole request headers of the client to the underlying endpoint you request to (leading to no user session if doing internal routing). Related issue to my last comment: https://github.com/nuxt/nuxt/issues/24813
6 replies