与Firebase身份验证反应:如何设置持久性?

问题描述 投票:0回答:1

我的登录名遇到错误:

const Login = ({ history }) => {
const handleLogin = useCallback(
    async event => {
        event.preventDefault();
        const { email, password } = event.target.elements;
        try {
            await app
                .auth()
                .signInWithEmailAndPassword(email.value, password.value);
            app.auth().setPersistence(app.auth.Auth.Persistence.SESSION);
            history.push("/feed");
        } catch (error) {
            alert(error);
        }
    },
    [history]
);

我认为我的setPersistence放在错误的位置,但我不知道如何解决。我的导入列表:

import React, { useCallback, useContext } from "react";
import { withRouter, Redirect } from "react-router";
import app from "../../firebase";
import { AuthContext } from "../../Auth";

谢谢!

javascript reactjs firebase firebase-authentication
1个回答
0
投票

您必须在调用signInWithEmailAndPassword之前调用setPersistence。

© www.soinside.com 2019 - 2024. All rights reserved.