Created
October 29, 2021 09:58
-
-
Save NyaGarcia/3bd59c5fb84664c6a82f39f52421385c to your computer and use it in GitHub Desktop.
Protecting the auth module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
AuthGuard, | |
redirectLoggedInTo, | |
redirectUnauthorizedTo, | |
} from '@angular/fire/auth-guard'; | |
import { RouterModule, Routes } from '@angular/router'; | |
import { NgModule } from '@angular/core'; | |
const redirectUnauthorizedToLogin = () => redirectUnauthorizedTo(['']); | |
const redirectLoggedInToHome = () => redirectLoggedInTo(['dashboard']); | |
const routes: Routes = [ | |
{ | |
path: '', | |
loadChildren: () => | |
import('./features/auth/auth.module').then((m) => m.AuthModule), | |
canActivate: [AuthGuard], | |
data: { authGuardPipe: redirectLoggedInToHome }, | |
}, | |
{ | |
path: 'dashboard', | |
loadChildren: () => | |
import('./features/dashboard/dashboard.module').then( | |
(m) => m.DashboardModule | |
), | |
canActivate: [AuthGuard], | |
data: { authGuardPipe: redirectUnauthorizedToLogin }, | |
}, | |
{ | |
path: '**', | |
redirectTo: '', | |
pathMatch: 'full', | |
}, | |
]; | |
@NgModule({ | |
imports: [RouterModule.forRoot(routes)], | |
exports: [RouterModule], | |
}) | |
export class AppRoutingModule {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment