-
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
Cannot store user's session in cookies storage after called "signIn" and "confirmSignIn" successfully. #13725
Comments
Hello, @cong-tri and thanks for opening this issue. Can you clarify what you mean by you, "transmitted into 'signIn' {username, password} and next step would be call "confirmSignIn" transmitted into challegeResponse to handle"? And to better understand how that second error you're seeing tied to the |
That error event was created by our company to handle the error of duplicate device id when logging in from 2 or more devices, only logged in on 1 device. That passed successfully and logged in successfully. And the only bug left is that I can't save the user's session in cookies so I can check if there is a session or not in the middleware with Nextjs that gets it from the cookies. |
and the parameter "errorException" is "[DUPLICATED_DEVICE]". |
@cong-tri, can you provide a screenshot or more details from the network tab logs of what's happening when these errors are happening? You should be able to go to the network tab in your dev tools and attach the har logs? More info here), but word of caution that we'd advise you to open the file and remove any sensitive data before posting it publicly in a Github issue here. |
hello @cong-tri. The Here are some helpful considerations for resolving the issue.
Also, are you experiencing this issue on Chrome, Firefox and Safari and during local development only? |
thanks for your advice. I will try it. |
i had tried to configure AWS Amplify just one time to work both on the server side (using Next.js) and on the client side. In my setup, i extracted the real public IP or domain from a variable named "host" in a function called header() within your layout.ts file on server side. This value could either be an internal IP address like "http://192.168.0.xxx:xxxx/xxx" for non-secure connections or a public-facing domain like "https://dev.xxxxx.com:xxxx/" for secure connections. Can be i made a mistake in the way to config amplify aws? |
I had config with {ssr = true} 3 files: server component, client file, server file to call "runWithAmplifyServerContext".
I had the bug: confirmSignIn could not auto access user session after call signIn and enable ssr = true, but not enable ssr = true could be successful and store anything else data of user at localStorage. |
"getAmplifyConfig.ts" file : |
middleware.ts :
|
@cong-tri, I think there's potentially a couple things we can do to isolate the issue here after looking through your above provided code.
If you're still experiencing the errors with |
Because i don't want to manual config, i want to config can be re-used. But i try to use manual config but it still cannot work for me. And i removed Amplify.configure(config, {ssr: true}) in server component layout.tsx. |
Hello @cong-tri. The problem lies in the browser rejecting the cookies due to a domain mismatch or the Let's try configuring Amplify on the client as showed below, "use client";
import React from "react";
import { Amplify } from "aws-amplify";
import { CookieStorage } from 'aws-amplify/utils';
import { cognitoUserPoolsTokenProvider } from 'aws-amplify/auth/cognito';
import { getAmplifyConfig } from "../../amplify-config";
const ConfigureAmplifyClientSide = ({
children,
domain,
}: {
children: React.ReactNode;
domain: string;
}) => {
const config = getAmplifyConfig(domain ?? "");
Amplify.configure(config, { ssr: true });
cognitoUserPoolsTokenProvider.setKeyValueStorage(new CookieStorage(
secure: !isLocalDevelopment() // If it is local development then the secure flag should be false, otherwise true.
));
return <>{children}</>;
};
export default ConfigureAmplifyClientSide;
|
thank @israx, @cwomack, @robbevan for give me advice. I recognize my main bug is that have not yet set up domain for cookie. I will try it. Thanks.
import { Amplify } from "aws-amplify"; cognitoUserPoolsTokenProvider.setKeyValueStorage( export default function ConfigureAmplifyClientSide() { |
@cong-tri are you still experiencing this? Just want to make sure I understood the comment above that you attempted to resolve this per @israx's advice in this comment and you're still experiencing an issue? |
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! (Please disregard the above linked PR, it was a typo) |
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth, api
Backend
None
Environment information
Describe the bug
Cannot store user's session in cookies storage after called Amplify.configure(config, { ssr: true }) and Auth Api "signIn" and "confirmSignIn" successfully, it just stored at localStorage.
I maked it with real domain / IP.
Expected behavior
I hope it after signIn successful can be stored in cookie storage.
Reproduction steps
const config = getAmplifyConfig(domain); // domain can get from real url domain
Amplify.configure(config, { ssr: true })
Code Snippet
Log output
aws-exports.js
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
The text was updated successfully, but these errors were encountered: