Closed Sizlers closed 6 months ago
Hi @Sizlers thanks for trying out the Next.js adapter. Have you configured Amplify on the client side specifying the "SSR" use case?
Amplify.configure({
... // your Amplify config object
}, {
ssr: true, // instruct the client to using cookie store storing auth tokens
})
If you have done so, could you check if the tokens are presented in the cookie store? Also check the requests sent out to your Next.js server, have cookies
header containing the tokens stored in the cookie store?
@Sizlers, can you also clarify how the Auth resources were created (i.e. through Cognito Console, were existing from previous app, etc) when you say they were not generated via amplify? Thanks!
I have the same problem, I checked the cookie is not in the cookie store, even though the ?code=***
exist in the url param, it is not being consumed by amplify.
Hi @adithep in what sign in flow you are seeing this issue? You mentioned ?code
query parameter, is that the OAuth flow? Can you give details of your set up, and how did you trigger this issue?
Same problem to me y Nextjs with SSR:
This function doesnt work:
const currentUser = await runWithAmplifyServerContext({
nextServerContext: { cookies },
operation: (contextSpec) => getCurrentUser(contextSpec)
});
Neither this one:
const currentUser = await runWithAmplifyServerContext({
nextServerContext: { cookies },
operation: async (contextSpec) => {
try {
const session = await fetchAuthSession(contextSpec);
The error is the same to me: NotAuthorizedException: Unauthenticated access is not supported for this identity pool.
@Sizlers and @adithep, circling back to this issue now that we're well past the pre-release versions of v6. Have either of you tried to upgrade to the most recent versions of Amplify v6 and see if you're still experiencing this issue?
@rallona, the v6 fetchAuthSession()
API will potentially fail in that way if the identityPool is not set up properly. If you're still experiencing this issue, can you check the identityPool to ensure it matches with the userPoolId? In the event this persists, we'll ask you to open a new issue tied to this because it appears to be different than what @Sizlers is experiencing.
Closing this issue as we have not heard back from you. If you are still experiencing this, please feel free to reply back and provide any information previously requested and we'd be happy to re-open the issue.
Thank you!
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
Authentication
Amplify Categories
auth
Environment information
Describe the bug
When I use an existing cognito userpool/client app everything works as expected on the client side, being able to log in/register/sign out.
However the session is not getting picked up in NextJS's middleware.
Adding auth through amplify works as expected however and the session is getting passed through to the middleware.
On the amplify userpool, I then created a app client with the default settings:
Settings: App type: Public Client App client name: test-client Client secret: Don't generate a client secret Authentication flows: ALLOW_USER_SRP_AUTH Authentication flow session duration: 3 minutes Refresh token expiration: 30 days Access token expiration: 60 minutes ID token expiration: 60 minutes Enable token revocation: true Prevent user existence errors: true
Then plugged in that application client, and the issue returns.
Expected behavior
runWithAmplifyServerContext to detect session with userpools not generated through amplify
Reproduction steps
Install the following project: https://github.com/nadetastic/amplify-v6-ssr-dev-preview
Add a pre-existing userpool client pool via the config which wasn't generated via amplify.
Register then login on the client side
See session not getting picked up on the serverside
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
{ "aws_cognito_region": "eu-west-2", "aws_user_pools_id": "eu-west-2_Nxov6QmH3", "aws_user_pools_web_client_id": "5kn63dvgueufnhoi88r05vurl5", }
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