我正在通过Google进行AWS登录,我已经登录,并且已经打印了警报。但是问题是我登录后进入catch错误。我已打印警报,如代码中所示,登录后我得到了13条警报。 Alert.alert(“ 13”); 有App.js类,其中Google按钮附加了登录Google。我正在编写auth类的代码,该过程在通过Google进行AWS登录之间进行。我在github中关注了此链接。 https://github.com/patw0929/react-native-amplify-cognito-example
export const loginGoogle = () => {
return new Promise(async(resolve, reject) => {
const user = await GoogleSignin.signIn().catch(error => {
// console.log('WRONG SIGNIN', error);
console.log('getOpenIdToken', getOpenIdToken);
Alert.alert("13");
});
if (user) {
const credential = await googleGetCredential();
if (credential) {
const result = await getOpenIdToken('accounts.google.com',
credential.identityId, credential.idToken);
resolve(result);
Alert.alert("8");
return;
}
reject('Authentication failed');
console.log('failed');
Alert.alert("9");
return;
}
return;
});
};
export const getOpenIdToken = async(provider, identityId, token) => {
const payload = {
IdentityId: identityId,
Logins: {
[provider]: token,
},
};
Alert.alert("10");
try {
const rsp = await fetch(COGNITO_IDENTITY_API, {
method: 'POST',
headers: new Headers({
'X-Amz-Target': 'AWSCognitoIdentityService.GetOpenIdToken',
'Content-Type': 'application/x-amz-json-1.1',
random: new Date().valueOf(),
'cache-control': 'no-cache',
}),
body: JSON.stringify(payload),
});
if (!rsp.ok) {
logout();
} else {
const json = await rsp.json();
return json.Token;
}
} catch (e) {
console.log('Error of getOpenIdToken: ', e);
}
};
const googleConfigure = () => {
GoogleSignin.hasPlayServices({
autoResolve: true
})
.then(() =>
GoogleSignin.configure({
iosClientId: GOOGLE_SIGNIN_IOS_CLIENT_ID,
webClientId: GOOGLE_SIGNIN_WEBCLIENT_ID,
})
);
};
export const init = () => {
googleConfigure();
};
我想要令牌以在警报中打印。 任何帮助将不胜感激。
答案 0 :(得分:0)
enter image description here布拉姆,在这个问题上,很多信息都丢失了。至少,错误消息必须存在
完整文档在这里 https://itnext.io/google-sign-in-using-aws-amplify-and-amazon-cognito-69cc3bf219ad