Skip to content

Instantly share code, notes, and snippets.

@av1v3k
Created June 5, 2024 14:27
Show Gist options
  • Save av1v3k/c4755c51d8dd4e998f66714f78b494d4 to your computer and use it in GitHub Desktop.
Save av1v3k/c4755c51d8dd4e998f66714f78b494d4 to your computer and use it in GitHub Desktop.
authguard as function in angular 16 - example
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