我使用离子6.当使用功能loginwithgoogle使用firebase,它的工作完美没有任何错误在te web.它带我到正确的页面“主要”,但任务是设置应用程序在Android移动的.把谷歌帐户信息和点击登录后,它带我到其他页面localhost/登录未找到.
async loginWithGoogle() {
try {
const provider = new GoogleAuthProvider();
const auth = getAuth();
signInWithPopup(auth, provider).then(async (result: any) => {
//console.log(result)
const credential =
GoogleAuthProvider.credentialFromResult(result);
//console.log(credential)
const googleCredentials = {
id_token: result.user.accessToken,
email: result.user.email,
name: result.user.displayName
};
//console.log(googleCredentials)
const body = JSON.stringify({
google_credentials: googleCredentials
});
const parsedBody = JSON.parse(body);
const idToken = parsedBody.google_credentials.id_token;
const headers = new HttpHeaders({
'Authorization': idToken
});
const response: any = await this.http.post(`${this.apiUrl}/login`,
body, {
headers
}).toPromise();
this.token.setToken(response.token);
await this.storage.set('auth-token', response.token);
this.router.navigate(['/principal']);
})
//await this.afAuth.signInWithRedirect(new firebase.auth.GoogleAuthProvider());
} catch (error) {
console.error('Error logging in with Google:', error);
}
}
1条答案
按热度按时间9lowa7mx1#
在Android上,你必须使用Firebase Android SDK。已经有电容器插件用于此。
示例:
Source
披露:我是
@capacitor-firebase/authentication
的维护者。