Closed IgorDePaula closed 1 year ago
Hey @IgorDePaula 👋 Thank you for raising this issue. I am not too familiar with NextAuth but if you're using Amplify in a SSR context, we provide this withSSRContext
utility function to reinitialize Amplify libraries on the server to help maintain user session between pages. Have you tried using this yet?
@chrisbonifacio Thank you for response. No, I'm not using nextjs with SSR. 3 weeks ago I'm using amplify without authenticator components on nextjs, but it stopped from anywhere. Now I can singIn with user, but any pages, any resources recognize the user, I'm using nextjs 11.
@IgorDePaula are you able to log the user on the client side with Auth.currentAuthenticatedUser
to confirm that Amplify still has the credentials to pass to API.graphql
? I don't know how NextAuth works but if you're already using Amplify/Cognito to manage your user's session, I don't know that you would need it.
EDIT: From reading the NextAuth documentation, it seems to me that the authentication does indeed happen on the server. There would be no way, as far as I can tell, for the Amplify instance created on the client to have been properly configured and be able to authorize API.graphql
calls automatically. The way we recommend persisting user session (in an Amplify project) between requests for the user is to use the withSSRContext
utility function which has to reinitialize Amplify on the server in order to properly create and use credentials for other categories such as API
and DataStore
.
@chrisbonifacio I discovery that I developed the app in mock api, all works fine, Thinking that next auth was syncronizing with nextauth, but no. I got authenticate an user with nextauth and amplify using credentials, but the cookies/session is not passed to nextauth, with this, in anothr pages the auth amplify module not recognize the authenticated user. I have/must/need/obligatory use authenticator from amplify, I can't use next auth only auth module from amplify.
This is bad, vary bad.
Right, there's no connection at the moment between Amplify and NextAuth. I labeled this as a feature request for the team to consider adding support for in the future.
Thank you very much
@chrisbonifacio my try https://gist.github.com/IgorDePaula/f3db1e5c4e7c94603f356dd76881d7f5
Just out of curiosity, could you try calling Amplify.configure({...awsconfig, ssr: true}) under the imports of your index.js file and see if the API calls are authenticated afterwards? It may require refreshing the page after sign in or perhaps the redirect to the dashboard will suffice.
I'll try.
@chrisbonifacio You're right. Now the amplify try set something on navigador.
But with ssr not works.
Hello, @IgorDePaula. In reviewing some of the older issues in our repo, I came across this one and wanted to check in to see if you found a workaround or solution yet. NextAuth is still not supported "out of the box" with Amplify at this time (making this feature request still valid), but let us know if there's any further context or progress you were able to make. Thanks!
@cwomack No, I'm not using next-auth with amplify. I understand how works it now.
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
GraphQL API
Amplify Categories
auth
Environment information
Describe the bug
In nextjs 11, The Auth from amplify get authenticated user, but the API not. The Auth passes the user to next session, I get session with the user but the API not.
Expected behavior
The API from amplify got authenticated user automatically.
Reproduction steps
Code Snippet
Log output
aws-exports.js
/ eslint-disable / // WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.
const awsmobile = { "aws_project_region": "us-east-1", "aws_cognito_identity_pool_id": "us-east-1:b57b4029-e7ec-4ac3-9fe8-fd228axxx", "aws_cognito_region": "us-east-1", "aws_user_pools_id": "us-east-1_NBb11vxuxxxx", "aws_user_pools_web_client_id": "4qu3b114r3d7at7uupxxx6v", "oauth": {}, "aws_appsync_graphqlEndpoint": "https://iungoxxxi.appsync-api.us-east-1.amazonaws.com/graphql", "aws_appsync_region": "us-east-1", "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS" };
export default awsmobile;
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response