chrisen
September 13, 2023, 7:31am
1
I got a problem with my vue application with Auth0.
I implemented auth0 inside my vue3 application according to the provided manual:Vue.js Authentication By Example: Composition API
I used as well the appState.
<template>
<div>
<q-btn
label="Login"
@click="login()"
/>
</div>
</template>
<script>
import { useAuth0 } from "@auth0/auth0-vue";
export default {
setup() {
const { loginWithRedirect } = useAuth0();
return {
login: () => {
loginWithRedirect({
appState: { target: "/app/test" },
});
},
};
},
};
</script>
I am redirected to the authentication page (auth0) and can successfully login and be redirected to my callback page.
The problem is - that’s it. I don’t get redirected to “/app/test” or “/”.
According to the manual - I should be redirected to “/” if I don’t have the appState set. I tried both - I always get stuck on the callback page.
No errors or whatever - user is also successfully logged in.
I know - I could cheat with a redirect on the callback page with router.push(), but that’s not what I want - I want to pass some url parameters from the login page.
Can anyone help me?
chrisen
September 14, 2023, 4:36am
2
Found the solution - it happened to be a problem with quasar and auth0-vue
For anybody who’s interested, check out the issue on GitHub
opened 05:23PM - 04 Sep 23 UTC
closed 03:19PM - 05 Sep 23 UTC
bug
### Checklist
- [ ] The issue can be reproduced in the [auth0-vue sample app](h… ttps://github.com/auth0-samples/auth0-vue-samples/tree/master/01-Login) (or N/A).
- [X] I have looked into the [Readme](https://github.com/auth0/auth0-vue#readme), [Examples](https://github.com/auth0/auth0-vue/blob/main/EXAMPLES.md), and [FAQ](https://github.com/auth0/auth0-vue/blob/main/FAQ.md) and have not found a suitable solution or answer.
- [X] I have looked into the [API documentation](https://auth0.github.io/auth0-vue/) and have not found a suitable solution or answer.
- [X] I have searched the [issues](https://github.com/auth0/auth0-vue/issues) and have not found a suitable solution or answer.
- [X] I have searched the [Auth0 Community](https://community.auth0.com) forums and have not found a suitable solution or answer.
- [X] I agree to the terms within the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md).
### Description
I am migrating to the new auth0-vue library. So far it has been a smooth ride but I am struggling with the last step. I want to return my users to the page they were initially routed to after they are successfully authenticated. There are two ways a user is asked to authenticate. Either by visiting a protected route or through a button on a login page.
The login page uses the `loginWIthRedirect` function:
```
auth0.loginWithRedirect({
authorizationParams: {
connection: <tenantId>,
redirect_uri: window.location.origin + '/pub/callback',
},
appState: {
target: '/default-route',
},
})
```
Protected routes use a route guard:
```
createAuthGuard({
app,
redirectLoginOptions: {
authorizationParams: {
connection: <tenantId>,
redirect_uri: window.location.origin + '/pub/callback',
},
},
})
```
The callback route is not protected and only displays a loading page without any logic. From what I read in the documentation and examples I would expect my callback route to be called. Afterwards, the state is extracted and the user is routed to the intended page.
The router is configured with the following routes:
```
const routes: RouteRecordRaw[] = [
{
path: '/',
name: availableRoutes.app_base,
component: () => import('layouts/MainLayout.vue'),
redirect: { name: defaultRoute },
children: [
{
path: '',
name: defaultRoute,
props: true,
component: () => import('pages/PersonalDashboardPage.vue'),
},
...
],
},
{
path: '/pub/',
component: () => import('layouts/PublicLayout.vue'),
children: [
{
path: 'login',
name: availableRoutes.login,
props: true,
component: () => import('pages/public/LoginPage.vue'),
},
],
},
{
path: '/pub/',
component: () => import('layouts/FakeMainLayout.vue'),
children: [
{
path: 'callback',
name: availableRoutes.callback,
props: true,
component: () => import('pages/public/LoginCallbackPage.vue'),
},
],
},
{
path: '/:catchAll(.*)*',
redirect: { name: defaultRoute },
},
];
```
### Reproduction
Step 1: Configure the library as stated above
Step 2: Visit the protected route or click the login button
Step 3: Provide credentials
Step 4: The callback page is displayed
Step 5: No redirect to the intended page
I can observe that the URL is changed to `window.location.origin` without the `code` and `state` parameters. However, the site is not refreshed.
### Additional context
I am using the Quasar framework (v2.12.5).
I ensured that the router was initialized before auth0. The route guard is created with the correct Vue instance.
### auth0-vue version
2.3.1
### Vue version
3.3.4
### Which browsers have you tested in?
Chrome, Edge, Firefox
system
Closed
September 28, 2023, 4:37am
3
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.