[英]Error while AWS login through google in react native
我正在通過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();
};
我想獲取令牌以在警報中打印。 任何幫助將不勝感激。
在這里輸入圖像描述 Bram,在這個問題上,很多信息都丟失了。 至少,錯誤消息必須存在
完整的文檔在這里https://itnext.io/google-sign-in-using-aws-amplify-and-amazon-cognito-69cc3bf219ad
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.