Skip to content

Commit

Permalink
fix: Auth0 state not been removed with vue-router WebHashHistory mode (
Browse files Browse the repository at this point in the history
…fixes #121) (#126)

* chore(git): add local build file to .gitignore

* fix: Auth0 state not been removed with vue-router  WebHashHistory mode (fixes #121)
With vue-router WebHashHistory mode the state properties in the url after login where not removed.
  • Loading branch information
jnt0r authored Aug 7, 2021
1 parent 6f7e170 commit 2550f65
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.idea/
/dist/
/coverage/
/vue-auth0-plugin-0.0.0-semantically-released.tgz
4 changes: 4 additions & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ async function initialize (app: App, authClient: Auth0Client): Promise<void> {
// handle the redirect and retrieve tokens
const { appState } = await client.handleRedirectCallback();

window.history.replaceState(
{ ...window.history.state, code: undefined, state: undefined },
document.title, window.location.pathname);

// Notify subscribers that the redirect callback has happened, passing the appState
// (useful for retrieving any pre-authentication state)
app.config.globalProperties.$router.push(appState && appState.targetUrl ? appState.targetUrl : '/');
Expand Down
12 changes: 12 additions & 0 deletions test/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ describe('initialize', () => {
expect(Plugin.properties.client).toEqual(client);
});
});

it('should remove code and state properties from historystate', async () => {
window.history.pushState(
{ someOtherProperty: 'ShouldStayInState', code: 'SomeCode', state: 'SomeState' }, '', '');

expect(window.history.state).toEqual(
{ someOtherProperty: 'ShouldStayInState', code: 'SomeCode', state: 'SomeState' });

return Plugin.initialize(app, instance(client)).then(() => {
expect(window.history.state).toEqual({ someOtherProperty: 'ShouldStayInState' });
});
});
});

describe('methods should be delegated', () => {
Expand Down

0 comments on commit 2550f65

Please sign in to comment.