Closed ulisescarreonalvarez closed 4 months ago
Hi @ulisescarreonalvarez
Firstly, looking at your code examples, when isLocalhost === false
, you are setting cookie domain as shedcloudtest.com
, is this the domain that your web app is hosted on?
Secondly, you are in your cookieConfiguration
you have not specified path
. Amplify requires setting auth token in cookie store with path: '/'
so it can retrieve the auth token when needed. If you are not setting path to the root, by default your auth token may be set to the path component in the current url. e.g. /auth/session/external
, which makes the auth token cookies only be accessible when the url matches the path.
Can you confirm the above items and try again?
I added the path before:
export const cookieConfiguration = {
secure: !isLocalhost,
sameSite: isLocalhost ? 'lax' : 'none',
path: "/"
};
But the cookies doesnt create at all when is Social Login, the code is received on my path but the is stuck loading, no error whatsover but is because no cookies are created automatically, i tried to add path, and add the domain direclty, trying to use lax, none, etc but the issue is persisting on Social Login.
Thanks for the follow up @ulisescarreonalvarez
But the cookies doesn't create at all when is Social Login
Do you call the signInWithRedirect()
API to initiate the social sign in flow (this is required)?
If "yes", is mydomain.com/auth/session/external/signin
where you called the signInWithRedirect()
API from? If "no" please take a look at this documentation.
Also could you confirm was there a fetch
call made to custom-domain.auth.us-east-1.amazoncognito.com/oauth2/token
for exchanging tokens after redirecting back to mydomain/auth/session/external/signin
?
So, im calling signInWithRedirect on my login page, the auth/session/external/signin is a redirect path that i had before on the application user pool, i never exchange code for tokens, the cookies usually are created automatically on the App, the issue is new for use with the new gen of amplify, we neved had an issue with the cookies until Gen 2 on our new project using an existing application :
const AuthLogin = () => {
const navigation = useNavigate();
const [checked, setChecked] = React.useState(false);
const [verification, setVerification] = React.useState(false);
const { login } = useAuth();
const scriptedRef = useScriptRef();
const [showPassword, setShowPassword] = React.useState(false);
const handleClickShowPassword = () => {
setShowPassword(!showPassword);
};
const handleMouseDownPassword = (event) => {
event.preventDefault();
};
const signInWithGoogle = () => {
signInWithRedirect({ provider: "Google" })
};
called on a button.
<Grid item xs={12}>
<AnimateButton>
<Button
id="googleSignInButton" // Add this id to the button element
disableElevation
fullWidth
size="large"
type="button"
variant="dashed"
color="error"
startIcon={<GoogleOutlined/>}
onClick={signInWithGoogle}
>
<FormattedMessage id="google-login" />
</Button>
</AnimateButton>
</Grid>
So, im calling signInWithRedirect on my login page, the auth/session/external/signin is a redirect path that i had before on the application user pool
Is your login page and auth/session/external/signin
under the same domain? Is your app a single page application and is auth/session/external/signin
a route of the SPA app?
the issue is new for use with the new gen of amplify, we neved had an issue with the cookies until Gen 2 on our new project using an existing application :
To clarify, your existing application uses also Amplify v6, and it works with your Gen1 backend resource? Amplify JS v6 remained the same between Gen1 and Gen2, there is no difference on the library side.
Also could you confirm was there a fetch call made to custom-domain.auth.us-east-1.amazoncognito.com/oauth2/token for exchanging tokens after redirecting back to mydomain/auth/session/external/signin?
Can you watch this in the network tab in developer tool? This is handled by the library, if you don't see this happening while redirecting back to auth/session/external/signin
that means something disturbs the social sign in flow, and we need to identity the root cause.
Ok, so is a multi-page, we are using routing for the application (react-router-dom).
Yes, the path is in the same project.
Backend is the same for the project, we have another project (old amplify version) that works fine with the cookies.
The network, works fine, it returns the code and the state but is stuck on the cookie creation because the getCurrentUser wont call it, like the useEffect not working because the library seems to not to finish the procces.
If it's a multipage application, and the route auth/session/external/signin
doesn't bundle signInWithRedirect()
API call, you would need to follow this documentation to do one extra setup.
That seems to make it work, thanks!
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Authentication
Amplify Version
v6
Amplify Categories
auth
Backend
Other
Environment information
Describe the bug
Im unable to create the session cookies for the Social Login.
Funny thing is that the session is workin with email and password but not when social login is made. In Localhost enviroment the cookies work tought.
Expected behavior
The cookie behaivor needs to be created for domain like a usual login request.
Reproduction steps
Code Snippet
My Component for the code response:
It only seems to work with the same Cognito App Integration with redirect url for localhost but not for a live domain.
https://mydomain.com/auth/session/external/signin?code=zzzzz-9ca9-4f0a-b016-319f270ec78c&state=zzzzzzz
This example of the response code do nothing on live domain with the component so ,getCurrentUser doesnt bring any data and no cookies are created.
Log output
aws-exports.js
Manual configuration
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