Open ipanamski opened 2 months ago
Hey,
This is called intended redirect (I'm working on a module) but you have to store the current path in a cookie when your Nuxt Middleware detect that the user should be logged in.
Then, in the onSuccess
, you just have to get the cooke value and to redirect to it or the default value if it does not exists.
How can I implement this currently as there is no access to the current route outside of onSuccess? I don't want to store the cookie on 10 different places for each scenario where the user logs in.
Can't we add a beforeRequest method that exposes the h3 event, to the event handler interface, so we can set a cookie there?
In your Nuxt application (./app
), you should have a middleware named auth
or similar that restrict access to some parts of your application. Within the middleware, you use the composable useCookie
, https://nuxt.com/docs/api/composables/use-cookie to write a cookie with the route that the user want to access using from
.
Then, in the Nitro part (server
), you can read this cookie and redirect the Nuxt app to this page.
What about the case when a user just clicks a login button in the toolbar from some of the pages (which is a direct link to /auth/github
)? I would need to set a cookie on every page the user visits. I'm talking about the scenario when the user logs in willingly, without being forced into a login page.
You can intercept the click, set the cookie and then redirect using navigateTo
.
I'm trying to make the plugin redirect to the page from which the user navigated to
/auth/github
. I can't get the ''Referer" header, since I can't access the event object outside of onSuccess. What is the recommended method and can we add it to the documentation?