-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authenticator component returns idle in authenticated state #1332
Comments
Thanks @dmost714 ! As a work around, instead of using the We'll add this to our roadmap, in our next major release. |
A smaller workaround could be to put an invisible |
That works. Thanks for the suggestion. I added the Authenticator component w/ hidden class. If I'm not logged in, I only see my marketing page. If I am logged in and hard-reload the page on the / path, the placeholder auth component causes the Workaround:
Full context:
|
Could you elaborate on why that works? In July, 2023, this still seems to be an issue.
|
I finally figured out something, use const { authStatus } = useAuthenticator(context => [context.authStatus]); instead of route, and check for unauthenticated. here is my RequireAuth.jsx ` export function RequireAuth({ children }) { if(authStatus === 'unauthenticated'){
} I spent a good few hours messing around with this I hope it helps someone else who might be haivng issues with route returning 'idle' and making the example code given not work. |
Before creating a new issue, please confirm:
On which framework/platform are you having an issue?
React
Which UI component?
Authenticator
How is your app built?
vite
Please describe your bug.
TLDR; If I'm signed-in and reload the browser window, I return to my marketing page instead of the dashboard page.
I'm using the
context.route
fromuseAuthenticator
to determine if I should follow the authenticated or unauthenticated code path. If I'm authenticated (signed in via theAuthenticator
component), and reload the webpage, the context.route value returnsidle
instead of the expectedauthenticated
. This results in the wrong code path being executed. If the<Authenticator>
component is used in this state, it skips through sign-in and shows it's children components (my app).What's the expected behaviour?
If I'm signed-in and reload the webpage, the route returned by
useAuthenticator
should returnauthenticated
instead ofidle
.Help us reproduce the bug!
If a complete working example is needed, let me know.
Here's an explanation of the code snippet below...
I catch the route from useAuthenticator() and use it to return my dashboard routes (authenticated) or the marketing routes (unauthenticated).
The marketing routes show the marketing page and a 'sign-up/sign-in' button that goes to an '/enter' route.
The marketing page shows for "/", any other route resolves to the
<Authenticator />
component.The marketing page has a button that navigates to 'enter', which leads to the
Authenticator
(per above).Once authenticated, the dashboard's '/enter' route re-route to '/'; showing the dashboard.
If an unauthenticated user visits a deep link, they sign-in and see the intended page.
Everything works, EXCEPT, if I'm signed in AND on the root page AND reload the browser page i'm taken to the marketing page. This is because useAuthenticator() is returning
idle
after the reload, instead ofauthenticated
. Due to the way I've setup routing, any other page will hit the authenticator component, skip though the sign-in and show the intended page.I believe this is a known issue. I inquired about it in the Discord channel and received this advice:
From Discord Amplify channel:
wlee221 — Today at 2:01 PM
Ah I believe this is a bug -- as of now
<Authenticator />
needs to be in the component tree for it to properly transition to the route 'authenticated' . This is false and a bad assumption...Code Snippet
Additional information and screenshots
No response
*edited by wlee221 for typo *
The text was updated successfully, but these errors were encountered: