我正在按照此处的步骤尝试将 Google 登录添加到使用的项目中。Firebase 授权。
data-fetcher-dev.firebaseapp.com包含在 Firebase 授权域中。我的代码:
firebase.initializeApp({
apiKey: 'AIzaSyCp8i_9lHCyLOREMIPSUM21342xXmb0F0Y',
authDomain: 'data-fetcher-dev.firebaseapp.com',
projectId: 'data-fetcher-dev',
});
const googleProvider = new firebase.auth.GoogleAuthProvider();
googleProvider.addScope('profile');
googleProvider.addScope('email');
...
const signInWithGoogle = async () => {
try {
const result = await firebase.auth().signInWithPopup(googleProvider);
console.log('result: ', result);
} catch (error) {
console.log('error: ', error);
}
};
Run Code Online (Sandbox Code Playgroud)
signInWithGoogle当按下按钮时调用。将打开一个新选项卡,我可以选择一个 Google 帐户/登录其中一个:
选择帐户后,我将被重定向到类似的 URL https://data-fetcher-dev.firebaseapp.com/__/auth/handler?state=LONG_TOKEN_VALUE&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&authuser=3&prompt=consent,并且该页面将永远加载:
我正在使用 firebase 托管,因此 处有一个空项目https://data-fetcher-dev.firebaseapp.com。我需要在 实现后端路由吗/__/auth/handler …
javascript oauth firebase firebase-authentication google-signin