I'm running into an error with my Login:
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]
);
I think that my setPersistence is at the wrong place but I don't know how to fix that. My import list:
import React, { useCallback, useContext } from "react";
import { withRouter, Redirect } from "react-router";
import app from "../../firebase";
import { AuthContext } from "../../Auth";
Thank you!
I'm running into an error with my Login:
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]
);
I think that my setPersistence is at the wrong place but I don't know how to fix that. My import list:
import React, { useCallback, useContext } from "react";
import { withRouter, Redirect } from "react-router";
import app from "../../firebase";
import { AuthContext } from "../../Auth";
Thank you!
Share Improve this question asked Dec 2, 2019 at 23:00 bnexdbnexd 1614 silver badges13 bronze badges1 Answer
Reset to default 4You have to call setPersistence before calling signInWithEmailAndPassword.
const Login = ({ history }) => {
const handleLogin = useCallback(
async event => {
event.preventDefault();
const { email, password } = event.target.elements;
try {
await app.auth().setPersistence(app.auth.Auth.Persistence.SESSION);
await app
.auth()
.signInWithEmailAndPassword(email.value, password.value);
history.push("/feed");
} catch (error) {
alert(error);
}
},
[history]
);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745346998a4623597.html
评论列表(0条)