Created
June 5, 2024 14:27
-
-
Save av1v3k/c4755c51d8dd4e998f66714f78b494d4 to your computer and use it in GitHub Desktop.
authguard as function in angular 16 - example
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
export const AuthGuard: CanActivateFn = (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => { | |
const store = inject(Store); | |
return new Promise<boolean>(resolve => { | |
const sub = store.select(getAgeSelector).subscribe(res => { | |
if (res && res?.token && res?.token?.length) { | |
resolve(true); | |
} else { | |
window.open(environment.WHATEVER, '_SELF'); | |
resolve(false); | |
} | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment