I use firebase and AngularFireAuthGuard to protect specific routes, so that only authenticated users are allowed to access them. In particular, my MainComponent and MgmtComponent should only be accessible to AUTHENTICATED users.
const redirectUnauthorizedToLogin = () => redirectUnauthorizedTo(['/login']);
const routes: Routes = [
{ path: 'teams/:teamId/sessions/:sessionId',
component: MainComponent,
canActivate: [AngularFireAuthGuard], data: { authGuardPipe: redirectUnauthorizedToLogin }
},
{ path: 'mgmt',
component: MgmtComponent,
canActivate: [AngularFireAuthGuard], data: { authGuardPipe: redirectUnauthorizedToLogin }
},
{
path: 'login',
component: LoginComponent
}
];
My Problem is, that the user is not redirected back to the originally requested URL, after a successful login. So what I want/expect is:
- user goes to
/mgmt
- as the user is not authenticated he is automatically redirected to
/login
- user authenticates (e.g. via google or Facebook OAuth)
- user is automatically redirected back to the originally requested page (
/mgmt
)
Steps 1-3 work fine, but step 4 is missing.
This is an open feature request, the angularfire team is working on it: https://github.com/angular/angularfire/pull/2448
Meanwhile I found this workaround: In the app-routing-module.ts instead of
I use following to store the url in the sessionStorage:
In the LoginComponent I read the value from the session storage to redirect: