Closed edbrix-school closed 1 year ago
Based on error 'logins' failed to satisfy constraint
, this maybe related to this issue/comment
Hello, @edbrix-school. To the point of @nadetastic's comment above, are you calling Amplify.configure()
more than once or updating the redirect URLS's for sign in/sign out?
@edbrix-school, a few more questions to help understand what's happening better and unblock you.
Amplify.configure()
within a useEffect hook by chance?Any code that you're willing to share that's related to the Sign-in flow or Amplify.configure()
would be helpful! Thank you.
Hello, I started receiving similar 400 errors on my app when using Google Sign In after updating to aws-amplify@5.3.7
, I did some testing and this errors are not happening on version 5.3.6
.
I'm using the Authenticator from @aws-amplify/ui-react
, when I click on the button to log-in with Google it looks like it's trying to sign-in, then I see the form again (as if nothing has happened) and get the 400 error on the console. Sometimes it logs in after seeing the form again and clicking again on the button, and others I get the error but it does log-in.
When adding Hub.listen('auth'...
here's the error I'm seeing on data.payload.event === 'signIn_failure'
:
{
"channel": "auth",
"payload": {
"event": "signIn_failure",
"data": {},
"message": "The OAuth response flow failed"
},
"source": "Auth",
"patternInfo": []
}
When looking at the console this are the errors I see:
POST https://***.auth.us-west-1.amazoncognito.com/oauth2/token 400
1 - Here's my attribute mapping
2 - As I'm using Next.js with the app
directory I'm calling Amplify.configure()
in a server
and a client
component on a layout
for it to be accessible across my whole app:
//app/layout.js
import AmplifyProviderServer from '@/hooks/AmplifyProviderServer';
import AmplifyProviderClient from '../hooks/AmplifyProviderClient';
export default function RootLayout({ children }) {
...
<AmplifyProviderServer>
<AmplifyProviderClient>
{children}
</AmplifyProviderClient>
</AmplifyProviderServer>
...
}
//hooks/AmplifyProviderServer.js
import { Amplify, Hub } from 'aws-amplify';
import awsmobile from '@/src/aws-exports';
let isLocalhost;
if (typeof window !== 'undefined') {
isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
);
}
const [localRedirectSignIn, productionRedirectSignIn] = awsmobile.oauth.redirectSignIn.split(',');
const [localRedirectSignOut, productionRedirectSignOut] =
awsmobile.oauth.redirectSignOut.split(',');
Amplify.configure({
...awsmobile,
oauth: {
...awsmobile.oauth,
redirectSignIn: isLocalhost ? localRedirectSignIn : productionRedirectSignIn,
redirectSignOut: isLocalhost ? localRedirectSignOut : productionRedirectSignOut
},
ssr: true
});
Hub.listen('auth', (data) => {
console.log('Whats going on here', data)
});
export default function AmplifyProviderServer({ children }) {
return <>{children}</>;
}
//hooks/AmplifyProviderClient.js
'use client';
import { Amplify, Hub } from 'aws-amplify';
import awsmobile from '@/src/aws-exports';
import { Authenticator } from '@aws-amplify/ui-react';
let isLocalhost;
if (typeof window !== 'undefined') {
isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
);
}
const [localRedirectSignIn, productionRedirectSignIn] = awsmobile.oauth.redirectSignIn.split(',');
const [localRedirectSignOut, productionRedirectSignOut] =
awsmobile.oauth.redirectSignOut.split(',');
Amplify.configure({
...awsmobile,
oauth: {
...awsmobile.oauth,
redirectSignIn: isLocalhost ? localRedirectSignIn : productionRedirectSignIn,
redirectSignOut: isLocalhost ? localRedirectSignOut : productionRedirectSignOut
},
ssr: true
});
Hub.listen('auth', (data) => {
console.log('Whats going on here', data)
if (data.payload.event === 'signIn_failure') {
console.log('Algo anda mal', data);
}
});
export default function AmplifyProviderClient({ children }) {
return <Authenticator.Provider>{children}</Authenticator.Provider>;
}
3 - I made the tests and I see the error in dev as well as production.
4 - Also not sure if relevant but I'm doing some account linking with preSignup and postAuth functions following this thread.
I encountered a very similar issue when upgrading the package to the latest version 5.3.7
using npm update aws-amplify
.
In the DevTools Network tab, I noticed that 2 POST requests were made to **.amazoncognito.com/oauth2/token
@an-nguyen-codeleap, this sounds related to what's described in issue #11808. Can you confirm that rolling back to v5.3.6 of Amplify resolves the errors you experience?
@edbrix-school as you stated in your comment above, this only seems to be happening in the most recent version. We are investigating the root cause of this and will update this issue along with #11808 soon with any findings or recommendations.
@an-nguyen-codeleap and @edbrix-school, the PR mentioned above was included in yesterday's release of v5.3.8 of Amplify. Can you see if upgrading to the most recent version resolves the issue please? Thanks!
@cwomack The lates update solved the issue for me, and it's now working great again, thanks.
@jerocosio, thank you for the confirmation!
@edbrix-school or @an-nguyen-codeleap, can you verify if upgrading to v5.3.8 resolves the errors for you as well?
@edbrix-school and @an-nguyen-codeleap, we've actually had 2 more releases since my last comment and are now on v5.3.10 for the latest version of Amplify. I believe the issues described in this issue should be resolved with the latest version, but want to see if we can get your confirmation before closing this issue. Thanks!
@cwomack I have the same setup and followed instruction given in this comment https://github.com/aws-amplify/amplify-js/issues/11786#issuecomment-1676031695 with amplify version v5.3.6 and 5.3.10 but I cannot resolve the error described in this issue.
@cwomack the latest version solved my issue. Thank you and the team for great work!
@an-nguyen-codeleap, appreciate the confirmation and happy to hear it!
@sky4git, interesting that the same setup wouldn't fix it for you but it did for @jerocosio. Can you share what you have in your package.json
please? Also, if you've upgraded to v5.3.10 already... can you try deleting your node_modules
as well as your package-lock.json
then reinstalling dependencies with npm install
results in the same errors?
Closing this issue as it appears to be resolved with multiple confirmations. If anyone is still experiencing this, please review the comments above and upgrade to v5.3.10 of Amplify or later.
Thank you!
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Authentication
Amplify Categories
No response
Environment information
Describe the bug
{"__type":"ValidationException","message":"1 validation error detected: Value '{cognito-idp.ap-south-1.amazonaws.com/ap-south-XXXXX}' at 'logins' failed to satisfy constraint: Map value must satisfy constraint: [Member must have length less than or equal to 50000, Member must have length greater than or equal to 1]"}
Expected behavior
Google Sign In need to work
Reproduction steps
NPM Install
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.
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