0
votes

I am using auth0 for authentication. In my angular app I have an AuthGuard to prevent routing to the angular app during authentication with auth0. During the authentication the url looks like this

     https://www.examplesite.com/#access_token=jlfdsfhWboAhvlRhbZt&expires_in=86400&id_token=aeryJ0eXAfsiOiJ..&token_type=Bearer&state=16d15855-0827-4189-bc34-26b981d578bb

The app contains the following routes

export const ROUTES: Routes = [
 { path: '', loadChildren: './home/home.module#HomeModule', canActivate:    [AuthGuard] },
 { path: '**', redirectTo: '/' },
];

Here is the AuthGuard:

@Injectable()
export class AuthGuard implements CanActivate {

constructor(private router: Router, private location: Location, private authService: AuthService) { }

   canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {

    if (route.fragment && route.fragment.startsWith('access_token')) {
        return false;
    }

    return true;
}
}

This works fine on localhost. The AccessToken path appears and after it disappears the app is loading successfully.

But it does not work on the published server. It shows the accesstoken path and it disappears the app isn't loaded.

In the console I get this warning #access_token=rfsdf...&expires_in=86400&id_token=rfafsdf...&token_type=Bearer&state=72e39d8b-7907-4fbb-88fb-1dd690622541:7 The key "" is not recognized and ignored.

Any idea why this works on localhost but not on the server?

1
Any errors in the browser console?Günter Zöchbauer
Hi @GünterZöchbauer I get one warning. Please see the updated answer at the bottom.doorman
hard to tell from here what the difference between localhost and the server is where you deployed it.Günter Zöchbauer
first try to build your app and working with your local iis and check if the error continue. second try to change localhost in your hosts file and check if the problem still existYoav Schniederman

1 Answers

0
votes

The problem was with Auth0 and handling hash. https://github.com/auth0/lock/issues/527