【发布时间】:2020-09-26 18:09:59
【问题描述】:
我正在尝试使用“@invertase/react-native-apple-authentication”库通过 firebase 实现苹果签名。
执行 signInWithCredential 方法时出现问题。 Firebase 返回错误:错误:[auth/invalid-credential] 提供的身份验证凭据格式错误或已过期
代码
export async function loginWithApple() {
// Start the sign-in request
try {
console.log('TRY');
const appleAuthRequestResponse = await appleAuth.performRequest({
requestedOperation: AppleAuthRequestOperation.LOGIN,
requestedScopes: [
AppleAuthRequestScope.EMAIL,
AppleAuthRequestScope.FULL_NAME,
],
});
console.log('CHECK TOKEN');
// Ensure Apple returned a user identityToken
if (!appleAuthRequestResponse.identityToken) {
throw 'Apple Sign-In failed - no identify token returned';
}
// Create a Firebase credential from the response
const {
nonce,
identityToken,
} = appleAuthRequestResponse;
if (identityToken) {
console.log(nonce, identityToken);
// Sign the user in with the credential
const appleCredential = auth.AppleAuthProvider.credential(
identityToken,
nonce,
);
auth()
.signInWithCredential(appleCredential)
.then((response) => console.log('loginWithApple', response))
.catch((error) => console.log('222222', error));
console.warn(
`Firebase authenticated via Apple, UID: ${userCredential.user.uid}`,
);
} else {
console.log('loginWithApple no token - failed sign-in');
}
} catch (error) {
...
}
}
有人可以帮帮我吗?
【问题讨论】:
-
嗨!希望你今天过得愉快。您能否指出我们需要在哪里正确输入服务 ID?谢谢
标签: javascript firebase react-native firebase-authentication