Skip to content

Commit 39fb3e8

Browse files
committed
feat(angular16): fix inject problem out of allowed zones
1 parent b97dc12 commit 39fb3e8

4 files changed

Lines changed: 17 additions & 19 deletions

File tree

src/app/modules/auth/auth.routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { LogoutPageComponent } from '~modules/auth/pages/logout-page/logout-page
77
import { noAuthenticationGuard } from '~modules/shared/guards/no-authentication.guard';
88

99
export const AUTH_ROUTES: Route[] = [
10-
{ path: authPaths.logIn, component: LogInPageComponent, canActivate: [noAuthenticationGuard()] },
10+
{ path: authPaths.logIn, component: LogInPageComponent, canActivate: [noAuthenticationGuard] },
1111
{
1212
path: authPaths.register,
1313
component: RegisterPageComponent,
14-
canActivate: [noAuthenticationGuard()],
14+
canActivate: [noAuthenticationGuard],
1515
},
1616
{
1717
path: authPaths.logout,
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import { userRoutes } from '~modules/user/shared/user-routes';
22
import { inject } from '@angular/core';
3-
import { CanActivateFn, Router } from '@angular/router';
3+
import { Router } from '@angular/router';
44
import { AuthRepository } from '~modules/auth/store/auth.repository';
55

6-
export function noAuthenticationGuard(): CanActivateFn {
7-
return () => {
8-
const authRepository: AuthRepository = inject(AuthRepository);
9-
if (!authRepository.isLoggedInValue()) {
10-
return true;
11-
} else {
12-
const router: Router = inject(Router);
13-
router.navigate([userRoutes.dashboard]);
14-
return false;
15-
}
16-
};
17-
}
6+
export const noAuthenticationGuard = () => {
7+
const authRepository: AuthRepository = inject(AuthRepository);
8+
if (!authRepository.isLoggedInValue()) {
9+
return true;
10+
} else {
11+
const router: Router = inject(Router);
12+
router.navigate([userRoutes.dashboard]);
13+
return false;
14+
}
15+
};

src/app/modules/user/user.routes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ export const USER_ROUTES: Route[] = [
1010
{
1111
path: userPaths.dashboard,
1212
component: DashboardPageComponent,
13-
canActivate: [authenticationGuard()],
13+
canActivate: [authenticationGuard],
1414
},
1515
{
1616
path: userPaths.myHeroes,
1717
component: MyHeroesPageComponent,
18-
canActivate: [authenticationGuard()],
18+
canActivate: [authenticationGuard],
1919
},
2020
{
2121
path: userPaths.myAccount,
2222
component: MyAccountComponent,
23-
canActivate: [authenticationGuard()],
23+
canActivate: [authenticationGuard],
2424
},
2525
{ path: '**', redirectTo: appPaths.error404 },
2626
];

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ bootstrapApplication(AppComponent, {
6161
link: ApolloLink.from([
6262
setContext((operation, prevContext) => ({
6363
headers: {
64-
...prevContext.headers,
64+
...prevContext['headers'],
6565
'Accept-Language': authRepository.locale,
6666
},
6767
})),

0 commit comments

Comments
 (0)