Async route guarding?
See original GitHub issueThanks for the great package! I was wondering if it’s currently possible to guard a route using an asynchronous function. It doesn’t seem to work with the implementation I have in the example below but I wasn’t sure if I was just doing something wrong:
#routes.js
# Check user consent status using a call to google firebase
async function checkConsent() {
try {
let resp = await db.collection('users').doc('test-user').get();
let consent = resp.data().consent;
return consent ? true : false;
} catch (error) {
console.error(error);
}
}
# Render the instructions route depending on the consent status of the user
export const routes = [
{
name: 'instructions',
component: Instructions,
onlyIf: { guard: checkConsent, redirect: '/exitSurvey' }
}
]
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (3 by maintainers)
Top Results From Across the Web
Angular2 canActivate() calling async function - Stack Overflow
When a navigate to a page that has the guard on it, either authenticated , or not authenticated is printed to the console...
Read more >Angular Async Guard Redirect - StackBlitz
Starter project for Angular apps that exports to the Angular CLI.
Read more >Async guards should have the option to wait for ... - GitHub
When having multiple async guards (returning promise or observable) for the same path they execute at the same time:.
Read more >An Example of An Asynchronous Route Guard
In this tutorial we are going to learn how we can to configure an can activate route guard in the Angular router. We...
Read more >Running Angular Guards Synchronously - Upmostly
... has multiple route guards, they will all run at once asynchronously. ... and the route will not navigate unless the guards succeed, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello @ejolly
Async functions are not supported now. But I’ll add that to the TODO list. I’ll let you know once it’s implemented.
In the same vein, it would probably be a good idea to have async component resolution for code splitting.