question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async route guarding?

See original GitHub issue

Thanks 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:open
  • Created 4 years ago
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
jorgegorkacommented, Nov 11, 2019

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.

2reactions
PierBovercommented, Mar 29, 2020

In the same vein, it would probably be a good idea to have async component resolution for code splitting.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found