-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
User authentication not persisted in browser: not authenticated #6555
Comments
After some digging in the code, I found a likely explanation, which could help to prevent this bug in the future. It looks like |
Another update: it looks like there is no session associated with the user. Maybe because I have MFA setup, but when I call If I delete the user pool and recreate it with MFA turned off, the login works. So my question is, what methods need to be called with MFA activated when doing the sign in manually? |
@janhesters I just stood up a Next.js sample following your steps and was able to get things working successfully. However, I noticed that after calling
I'd recommend giving https://docs.amplify.aws/ui/auth/authenticator/q/framework/react a try to at least validate that the flow works successfully for you using
When we ship #5435, we'll also include a Next.js sample here: |
@ericclemmons Thanks for trying to reproduce it, but no, the account is confirmed. Will built this up from scratch again and comment further below. We can't (or don't want to) use |
@janhesters I understand not wanting to use I'm hoping that'll tell is one of two things: whether the problem is with the client-side flow, or if there's a configuration/service problem. |
@ericclemmons @janhesters Had the same problem. Completing the flow with
Update: Calling Auth.completeNewPassword() after Auth.signIn() does solve this problem if signedIn with temp password initially. |
@janhesters Have you been able to research this further? Based on this comment, I'm curious if the root cause is with the complexity of Auth flows (with temp tokens, validation, etc.): |
Having the same issue, doesn't happen with withAuthenticator HOC. Problem is I cannot use the HOC as props do not get passed. [DEBUG] 57:26.508 AuthClass - getting current authenticated user meanwhile this page serverside redirects upon no authentication to a withAuthenticator page. this page shows that user is, in fact, logged in. logs: [DEBUG] 00:17.987 Amplify - component registered in amplify AuthClass {userPool: null, user: null, oAuthFlowInProgress: false, Credentials: CredentialsClass, currentCredentials: ƒ, …} |
@paragbaxi Can you share sample code for your scenario? |
@ericclemmons , my apologies, I don't have it as I ended up going the HoC route and calling appsync via the client side (on Next.js). If I run into it again, I'll paste it here. |
@janhesters Were you able to resolve the login flow issue? Based on the discussions before, our pre-built authenticator would've been used to validating that the backend/frontend are configured correctly. With that validated, then the solution would be in the implementation (e.g. calling |
This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems. |
I also got the same issue in my react app which use "aws-amplify": "^3.3.24". the user sign in successfully but when i refresh the page, first i call the "Auth.currentAuthenticatedUser" method to get the user data. but it always return "The user is not authenticated". |
Yeah this is a problem. Upgraded to amplify 4.0.3 and now when I try to run Auth.currentAuthenticatedUser() in my getServerSideProps function, it returns with 'The user is not authenticated', but when I run a helper function that runs Auth.currentAuthenticatedUser() in the same page outside the getServerSideProps function, it returns with the signed in user. Bewildering. Worked fine before the upgrade to amplify 4.0.3. |
I solved it using the exact version for I'm using a combination of the Here is the relevant part of
|
I solved this by adding the
|
Started a whole new project and problem went away, but I'll try the bypassCache if it pops up again. Thanks @beppek ! |
@beppek this does not seem to work. And for some reason, this only occurs for me on mobile or when being redirected back to the site |
@joekendal @eherms yeah it's weird. The day after I posted that it stopped working for me again for a different reason which I can't remember now. Removed That's the only thing I did that made it work at first though but now that it's gone it still works. Perhaps my cached user was messed up somehow 🤷♂️ |
If using getServerSideProps, is everyone also configuring Amplify with ssr to be true like so? Amplify.configure({ ...awsconfig, ssr: true }) This may fix the issue on the client but also with it you should be able to use withSSRContext in getServerSideProps to reinitialize Auth with the user credentials from the request. Please let me know if you are already doing this and still running into issues. If not, let me know if that helps at all. |
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs. Looking for a help forum? We recommend joining the Amplify Community Discord server |
Heads up
Opening this issue because all related issues seem to be closed WITHOUT an answer or solution for browsers, but many people face this problem.
Related issues:
Describe the bug
Authenticating the user in the browser and directly calling
currentAuthenticatedUser
results in an error. It looks like neither local storage nor cookie storage is being used to persist the session.To Reproduce
Steps to reproduce the behavior:
amplify init && amplify add auth
in a project. Choose defaults._app.js
in a Next.js app. (BUT I also just reproduced this with a regular CRA app).Auth.signIn
with valid credentials for a confirmed account. It returns a user correctly.Auth.currentAuthenticatedUser
. It throws an errornot authenticated
.If you set
Amplify.Logger.LOG_LEVEL = 'DEBUG';
this is the output:Expected behavior
currentAuthenticatedUser
should return the user correctly.Code Snippet
Add this to a button's
onClick
handler and click it. You get an error:'not authenticated'
What is Configured?
Only authentication as described above.
Environment
The text was updated successfully, but these errors were encountered: