0

Please or Register to create posts and topics.

Authentication doesn't work as it supposed to work

for example I shouldn't reach this page without being authenticated.

The user does not have access until they login.

To immediately redirect all users to the login page instead you can implement a canActivate guard for your Admin routes.

Change your admin-routing.module.ts to this (notice the addition of canActivate: [AuthGuard]):

const adminRoutes: Routes = [
    {
        path: 'admin',
        component: AdminComponent,
        children: [
            { path: 'users', component: UserListComponent, canActivate: [AuthGuard], data: { title: "Admin | Users" } },
            { path: 'roles', component: RoleListComponent, canActivate: [AuthGuard], data: { title: "Admin | Roles" } }
        ]
    }
];