firebase - Firebase google认证需要双击登录
问题描述
我尝试使用 google 身份验证(使用 React 挂钩)登录到 Firebase,我需要单击该按钮两次。我希望用户在第一次点击后进入主页。这里有什么问题?
googleLogin.js
import firebase from "firebase/app";
import { auth,app } from "../../../../config/firebase";
export const googleLogin = async (e, information, setInformation, signup, login, history) => {
var provider = new firebase.auth.GoogleAuthProvider();
firebase
.auth()
.signInWithPopup(provider)
.then( resp => {
let {user, credential,additionalUserInfo: userInfo} = resp;
let token = credential.accessToken;
if (userInfo.isNewUser) signupWithGoogle(user, credential, userInfo);
})
.then(()=>{
history.push('/')
})
.catch((error) => {
...
});
};
const signupWithGoogle = (user, credential, userInfo)=>{
app.firestore().collection('users').doc(user.uid).set({
firstName: userInfo.profile.given_name,
lastName: userInfo.profile.family_name});
const batch = app.firestore().batch();
const initData = [
{ Applied: { positionIds: [], title: 'Applied' } },
{ Contract: { positionIds: [], title: 'Contract' } },
{ Denied: { positionIds: [], title: 'Denied' } },
{ InProgress: { positionIds: [], title: 'In Progress' } },
{ ReceivedTask: { positionIds: [], title: 'Received Task' } },
];
initData.forEach((doc) => {
const docRef = app
.firestore()
.collection('users')
.doc( user.uid)
.collection('columns')
.doc(Object.keys(doc)[0]);
batch.set(docRef, Object.values(doc)[0]);
});
return batch.commit();
}
解决方案
I had the same problem to login and the problem was in my HTLM code. I was using a form. To resolve it, I used a simpler code in HTLM.
推荐阅读
- javascript - 如何将这个 HTML 元素数组组合成一个 React 组件
- r - 结合原始列名将列变量拆分为新列
- java - NIFI 中 DBCPConnectionPool 处理器的自定义加密或解密算法
- docker - Docker 2.0 EE 中的 K8S RBAC
- c - GCC SSA 格式中变量的含义
- oauth - 是否可以修改 WSO2 令牌响应?
- ubuntu - vim 大小不是终端的全尺寸
- .net-core - 获取 Azure AD JWT 令牌以在集成测试授权时使用
- javascript - 在 Keydown 事件上它应该播放匹配的音频
- reactjs - 来自 API 的 Reactjs 头像 src