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.

router guard and async

See original GitHub issue

Is there a particular way I need to use async functions within the wrap function? I’m trying to check authorisation from my API roughly like this.

    '/login': Login,
    '/facility': wrap(
      Facility,
      {},
      async (detail) => {
        const result = await authQuery()
        return await result
      }
      ),
    '*': Login,
  }

but I’m finding the route loads before the results from the api return.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
BogdanDariuscommented, Aug 1, 2020

I have the same issue, and I feel like the suggestion by @BogdanDarius isn’t general-purpose enough to (easily) work on many pages (please correct me if I misunderstood something). Simply passing an async function to wrap would be really nice!

Promise and lazy routing are on the roadmap. I encountered same issue while I wanted to implement code splitting.

1reaction
ItalyPaleAlecommented, Sep 20, 2020

@Manborough support for async functions in route pre-conditions has been added to 3.0 (WIP branch) and will be released with version 3.0 soon 🚀

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 >
Running Angular Guards Synchronously - Upmostly
I had a scenario where I had two route guards. The first was simply to check if the user was logged in via...
Read more >
Navigation Guards | Vue Router
Global before guards are called in creation order, whenever a navigation is triggered. Guards may be resolved asynchronously, and the navigation is considered ......
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