Add option to disable redirect when calling setUserToken or login #1594
Replies: 8 comments
-
"Hacky" work around we are using const oldRedirect = this.$auth.options.redirect;
this.$auth.options.redirect = false;
await this.$auth.setUserToken(response.token);
this.$auth.options.rewriteRedirects = oldRedirect; |
Beta Was this translation helpful? Give feedback.
-
I needed to overwrite the default redirects for a single route, and I ended up using something similar to @RyanMulready: mounted() {
this.oldRedirects = {
home: this.$auth.options.redirect.home,
logout: this.$auth.options.redirect.logout,
}
this.$auth.options.redirect.logout = false
this.$auth.options.redirect.home = '/collection/pending'
},
beforeDestroy() {
Object.assign(this.$auth.options.redirect, this.oldRedirects)
}, |
Beta Was this translation helpful? Give feedback.
-
Can you help me understand the scenario here? Why do you need to submit a form after the user is logged in? Isn't the form just logging the user in, and so the setUserToken is essentially the submit action? |
Beta Was this translation helpful? Give feedback.
-
My use case isn't really the same as @dansullivan86's. Here was my use case:
Does that make sense? I was thinking it would be nice to be able to override the default redirects per-component. Something like: BEFOREexport default {
// completely disable redirects for this route
auth: false,
components: { ... },
methods: { ... },
} AFTERexport default {
// change some redirects for this route
auth: {
login: '/different-than-default',
logout: false,
},
components: { ... },
methods: { ... },
} So the |
Beta Was this translation helpful? Give feedback.
-
@Anaphase Thanks for the explanation. Still wrapping my head around this a bit - are you describing an admin account takeover function? |
Beta Was this translation helpful? Give feedback.
-
@bmulholland No, not really an "admin takeover." I simply want to change the default auth redirects for any given page. In my particular case, I wanted to disable the default logout redirect (so they stay on the page after clicking the logout button) and the default login redirect (so they would go to a different post-login destination after logging in on this special page.) |
Beta Was this translation helpful? Give feedback.
-
Our use case was not a form, most of the time we want the user to be redirected to their homepage defined in Since then we've taken it a step further since we wanted more control over where and when the user is redirected. We disable the redirect in this module completely and handle the redirect ourselves. Something like below. Ultimately I think Login.vue await this.$auth.loginWith(name, options);
await this.$auth.handleUserRedirect(this.router); plugins/auth-extended.js export default async (ctx) => {
ctx.$auth.handleUserRedirect = async (router) => {
// Any if conditions can go here
router.push('/');
}
} |
Beta Was this translation helpful? Give feedback.
-
What problem does this feature solve?
My app has a form that includes a login as part of the flow. I need to log the user in, then submit the form and handle validation responses. Currently as soon as the user is logged in they are redirected. N.B I do use the login redirect for other login flows.
What does the proposed changes look like?
Add an options param to setUserToken / login that enables you to disable the redirect.
Beta Was this translation helpful? Give feedback.
All reactions