Reactjs Firebase github身份验证函数未记录值
我想知道为什么这些值没有登录到控制台。 我想访问结果对象,然后使用useState钩子设置用户。每当我单击“登录”按钮时。它不会将任何内容记录到控制台。只需登录用户,但我想访问存储在此处的username属性(result.additionalUserInfo.username) 请帮我解决这个问题Reactjs Firebase github身份验证函数未记录值,reactjs,firebase,firebase-authentication,Reactjs,Firebase,Firebase Authentication,我想知道为什么这些值没有登录到控制台。 我想访问结果对象,然后使用useState钩子设置用户。每当我单击“登录”按钮时。它不会将任何内容记录到控制台。只需登录用户,但我想访问存储在此处的username属性(result.additionalUserInfo.username) 请帮我解决这个问题 console.log(result.additionalUserInfo.username); console.log(result.additionalUserInfo.profile); 这
console.log(result.additionalUserInfo.username);
console.log(result.additionalUserInfo.profile);
这是我的密码
import React, { useState,useContext } from 'react'
import { createContext } from 'react';
import { useEffect } from 'react';
import {auth} from '../config/fbConfig'
const AuthContext = createContext();
export const useAuth = () => {
return useContext(AuthContext);
}
export const AuthProvider = ({children}) => {
const [currentUser, setCurrentUser] = useState();
const [loading, setLoading] = useState(true);
const provider = new auth.GithubAuthProvider();
// provider.addScope('user');
const githubSignIn = () => {
// return auth().signInWithRedirect(provider);
auth().signInWithRedirect(provider)
.then(function(result) {
console.log(result.additionalUserInfo.username);
console.log(result.additionalUserInfo.profile);
})
.catch(function(error) {
// Some error occurred.
console.log(error)
});
}
const githubSignOut = () => {
return auth().signOut();
}
useEffect(() => {
const unsubscribe = auth().onAuthStateChanged(user => {
// setCurrentUser(user);
setLoading(false);
})
return unsubscribe
}, [])
const value = {
currentUser,
githubSignIn,
githubSignOut
}
return (
<AuthContext.Provider value={value}>
{!loading && children}
</AuthContext.Provider>
)
}
import React,{useState,useContext}来自“React”
从“react”导入{createContext};
从“react”导入{useffect};
从“../config/fbConfig”导入{auth}
const AuthContext=createContext();
导出常量useAuth=()=>{
返回useContext(AuthContext);
}
导出常量AuthProvider=({children})=>{
const[currentUser,setCurrentUser]=useState();
const[loading,setLoading]=useState(true);
const provider=new auth.GithubAuthProvider();
//provider.addScope(“用户”);
常量githubSignIn=()=>{
//返回auth().signInWithRedirect(提供程序);
auth().signInWithRedirect(提供程序)
.然后(函数(结果){
log(result.additionalUserInfo.username);
log(result.additionalUserInfo.profile);
})
.catch(函数(错误){
//发生了一些错误。
console.log(错误)
});
}
常量githubSignOut=()=>{
返回auth().signOut();
}
useffect(()=>{
const unsubscribe=auth()。onAuthStateChanged(用户=>{
//setCurrentUser(用户);
设置加载(假);
})
退订
}, [])
常量值={
当前用户,
吉图宾,
githubSignOut
}
返回(
{!正在加载(&children}
)
}
请帮我解决这个问题