Use a function for options.redirect to inject Nuxt Context
#1589
gtnsimon
started this conversation in
Ideas & Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
What problem does this feature solve?
I'm using
@nuxtjs/authmodule in a Nuxt App for building a SaaS product where URLs contains the customer ID (e.g: https://nuxt.app/acme/login). In Nuxt, it could be represented to an URL like so in the router:/:customerId/login(in this example,:customerIdis equal toacme).Long story short : I have a Nuxt server middleware that checks if
acmeis an existing customer in database. If yes, I add it toreq.customerIdand finally insert it into my store using Nuxt StorenuxtServerInitaction. I now know the customer ID and can access it fromctx.store.customerId.In the current implementation of
options.redirect, we can use:It would be nice to have access to the Nuxt Context when defining
options.redirectso URLs can depends on and solve my needs (and others peoples too).What does the proposed changes look like?
We could use a function to define URLs for
options.redirect:Allowed return types should remain :
false,object.I did take a look in the source code of the Auth class used by the plugin, and redirects are handled by Auth.redirect function. Modifying it to check if it is a function is not a big deal.
It is also called from the auth middleware, that have access to the context.
I've tried on my machine but the problem is with defaults options.
options.redirectis dropped and the middleware return an error :ctx.$auth.options.redirect is not a functionwhich is normal.Thanks for your help and your awesome plug-and-play auth module!
Beta Was this translation helpful? Give feedback.
All reactions