我使用 React Native 和 aws amplify cognito 设置了 google auth。第一次登录时我收到此消息
登录失败ValidationException:检测到1个验证错误:“登录”处的值“{xxx.amazonaws.com/xxx}”未能满足约束:映射值必须满足约束:[成员的长度必须小于或等于50000,成员的长度必须大于或等于1]
第二次登录(按下按钮)时,它可以正常登录。
为什么无法先登录?为什么会收到此消息?
默认情况下,Amplify 将在 Safari/Chrome 中打开 Cognito 托管 UI,但您可以通过提供自定义 URL 打开器来覆盖该行为。
要解决使用 InAppBrowser 将给定 URL 转换为所需形式的问题,如 Ashish-Nanda 评论的ISSUE中所建议。
Amplify.configure({
...config, oauth: {
...config.oauth,
urlOpener: async function urlOpener(url, redirectUrl) {
await InAppBrowser.isAvailable();
const { type, url: newUrl } = await InAppBrowser.openAuth(url, redirectUrl, {
showTitle: false,
enableUrlBarHiding: true,
enableDefaultShare: false,
ephemeralWebSession: false,
});
// split according to ur received newURL
const splitUrl = `myapp://?${newUrl.split("#_=_")[0].split("?")[1] || ''}`;
if (type === 'success') {
Linking.openURL(splitUrl);
}
}
}
})