我正在使用Firebase auth
处理表单中的用户身份验证,但出现此错误
未定义的“持久性”错误
添加firebase.auth().setPersistence
时。
onSubmit = event => {
const { firebase } = this.props;
const { email, password, remember } = this.state;
firebase
.doSignInWithEmailAndPassword(email, password, remember)
.then(authUser => {
firebase.doEmailUpdateUser(authUser);
})
.then(() => {
this.setState({ error: null });
navigate(ROUTES.INDEX);
})
.catch(error => {
this.setState({
error,
errorOpen: true
});
});
event.preventDefault();
};
firebase.doSignInWithEmailAndPassword(email, password, remember)
是
doSignInWithEmailAndPassword = (email, password, remember) => {
this.auth
.setPersistence(
`${
remember
? this.auth.Auth.Persistence.LOCAL
: this.auth.Auth.Persistence.SESSION
}`
)
.then(() => this.auth.signInWithEmailAndPassword(email, password));
};
以供参考this.auth = app.auth();
我在这里错过了什么吗?我做错了什么?
答案 0 :(得分:1)
好像您正在尝试从错误的对象中获取Auth.Persistence
。您说this.auth = app.auth()
,所以我假设app
是从Firebase像import app from 'firebase'
导入的。如果不正确,请告诉我如何导入。
如果我的假设正确,那么您将需要访问app.auth.Auth.Persistence.LOCAL
之类的属性。您当前的版本更像app.auth().Auth.Persistence.LOCAL