-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Description
Version info
Angular: 8.0.1
Firebase: 6.2.0
AngularFire: 5.2.1
tsconfig.json "target": "es5"
Steps to set up and reproduce
- Setup a Firebase project with auth router guards https://github.com/angular/angularfire2/blob/master/docs/auth/router-guards.md and https://github.com/RaphaelJenni/FirebaseUI-Angular
- Use
...canActivate(redirectUnauthorizedTo(['login']))
like below:
const appRoutes: Routes = [
{
path: '',
...canActivate(redirectUnauthorizedTo(['login'])),
children: [
{ path: 'calendar', component: CalendarComponent },
{ path: '',
redirectTo: 'calendar',
pathMatch: 'full'
},
],
},
{
path: 'login',
component: LoginComponent,
...canActivate(redirectLoggedInTo([''])),
},
{ path: '**',
redirectTo: '/',
pathMatch: 'full'
},
];
- Everything works great with
ng serve
orng build
, but withng build --prod
, the router guardredirectUnauthorizedTo(['login'])
stops working. I.e., the user isn't redirected to /login, and can access the protected routes without logging in.
Debug output
There are no errors in the console. The redirection just doesn't occur.
Using RouterModule.forRoot(appRoutes, { enableTracing: true }),
confirms that.
With ng build
(redirection to /login works):
Notice that logging the AngularFireAuth.user observable (in yellow) shows that in the first case, it evaluated to null before the routing ended so the guard worked properly.
However, in the second case, the routing was performed before the auth state was evaluated (the observable hasn't emitted), and the guard didn't wait for it so it didn't work.
Expected behavior
Route guards should work with ng build --prod
.
Actual behavior
Route guards work with ng build
but not with ng build --prod
.
sasa95, pmc-sstaehle, helloejsulit, iislucas, tuanngominh and 19 more
Metadata
Metadata
Assignees
Labels
No labels