angular - Auth0 redirecting back to call url after login angular2 -


after login auth0 redirects me call url on angular2. how can make go path gave routing without redirecting call url.

i've been working through same issue.. seems have couple options.

a) use popup mode

this easy implement auth0 recommends not use because of browser inconsistencies. (namely ie , chrome/firefox on ios)

it's simple adding flag lock options object

var lockoptions = {   auth: {     redirect: false   } } 

popup mode docs

b) save state in localstorage

auth0 suggests saving state localstorage if want allow users resume left off.

so, before triggering lock.show(), save current url/path/state/etc local storage. in case, i'm using authguard.

canactivate(route: activatedroutesnapshot, state: routerstatesnapshot): promise<boolean> {     if (this.authservice.isloggedin) {         return promise.resolve(true);     }      // store attempted url redirecting after auth     localstorage.setitem('redirecturl', state.url);      // navigate login page     this.router.navigate([`${environment.loggedoutroute}`]);      return promise.resolve(false); } 

then inside auth callback:

// on authentication this.lock.on('authenticated', (authresult: any) => {     // save token in ls     localstorage.setitem('token', authresult.idtoken);      // hide login modal     this.lock.hide();      // redirect user     const redirecturl: string = localstorage.getitem('redirecturl');     if (redirecturl) {         this.router.navigate([redirecturl]);     } else {         this.router.navigate(['/overview']);     } }); 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -