Please include the following information in your post:
Which SDK this is regarding: auth0/auth0-angular
SDK Version: 1.10.1
Platform Version: Angular 12
Code Snippets/Error Messages/Supporting Details/Screenshots:
Hi Team,
I am using above mentioned sdk to configure Auth0 in my angular application.
I have imported AuthModule in my module.ts as below.
In my auth-callback component, I am want to get access token, but when I call ‘handleRedirectCallback’ then I get below error:
As per the stackoverflow thread, we dont need to call ‘handleRedirectCallback()’
angular, auth0
but as per the library comment, we should call this function:
It’s really confusing, can someone help here?
Thanks,
Jaydeep S
tyf
September 12, 2022, 10:43pm
2
Hey there @Jaydeeps03 !
I believe the documentation may be out of date here in saying that you need to call handleRedirectCallback()
directly:
opened 03:49AM - 03 Dec 21 UTC
closed 01:32AM - 06 Dec 21 UTC
bug report
### Describe the problem
I'm getting the error "Invalid state" when using the `… AuthGuard` on my routes. I have a setup where all my routes have that guard except for my callback route.
When trying to debug I set a breakpoint in `redirectIfUnauthenticated` and I am seeing some strange behavior where `isAuthenticated` is true, and then very shortly therafter it is false which causes the application to try and get a new token when it shouldn't. I believe that is causing the invalid state error.
![image](https://user-images.githubusercontent.com/16483662/144540784-b8a40093-282f-49fc-b914-f09459259308.png)
### What was the expected behavior?
I can see (on an app where it is working) that the "healthy" behavior is:
1. User is authenticated so `isAuthenticated` is true anytime its observed
2. User is not authenticated so `isAuthenticated` is false first and then `true` anytime its observed thereafter
### Reproduction
I tried to create an minimal reproducible example on a new application with the same version of angular and auth0/angular but haven't been able to reproduce which leads me to believe there is something in my code causing this issue. Is there anything you could recommend I look at to try and figure out why it thinks its unauthenticated when it actually is?
Things I've tried:
- observed the cookies to see if they change between states (they don't)
- looked for any instances of logout
### Environment
- **Version of `auth0-angular` used:**
- **Which browsers have you tested in?** Chrome
- **Which version of Angular have you tested with?** 10.1.5
- **Other modules/plugins/libraries that might be involved:** 1.8.0
hey I done some more research and come to know that we have to call handleRedirectCallback() function in call back URL. I was getting ‘Invalid State’ error because I made mistake while importing auth module, somehow I was initiating that twice in my application and this was causing generating two different states.
Hope this will help someone in future.
1 Like
tyf
September 20, 2022, 8:12pm
6
Awesome, good to know you were able to get this sorted and thanks for following up with the community
system
Closed
October 4, 2022, 8:12pm
7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.