我有Reactfirebase v9谷歌认证。
登入:
import { useNavigate } from 'react-router-dom';
const Login = () => {
const navigate = useNavigate();
const signInWithGoogle = async () => {
signInWithPopup(auth, provider)
.then((result) => {
const credential = GoogleAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
const user = result.user;
navigate('/'); // Redirect not work
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
const email = error.customData.email;
const credential = GoogleAuthProvider.credentialFromError(error);
});
};
....
<Button variant="dark" onClick={signInWithGoogle}>
Google
</Button>
...
如何在google注册后重定向到主页?
更新:问题
const credential = GoogleAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
const user = result.user;
1条答案
按热度按时间zrfyljdw1#
您可以使用react-router-dom提供的useNavigate钩子在成功通过Google身份验证后重定向到主页。
下面是一个示例,说明如何在Google身份验证后重定向到主页:
认证成功后,then块将被执行,它将调用navigate函数,以主页的路径作为参数,将用户重定向到主页。