【发布时间】:2021-09-15 04:31:34
【问题描述】:
我一直在使用 Firebase Auth(仅限纯电子邮件和密码)开发我的第一个 React Native 项目。 登录、注销、重置密码等......一切都很好,但我被一件事困住了,我需要删除用户的帮助。 因为删除用户是一个“敏感”请求,Firebase Auth 要求在实际删除用户之前重新对用户进行身份验证。 这是我不知道该怎么做的地方。即使是docs 也没什么好说的。他们的字面意思是:“TODO(you): prompt the user to re-providing their sign-in credentials”。
错误消息: TypeError: undefined is not an object (评估 '_firebase.auth.EmailAuthProvider.credential')
我的 firebase.js:
import firebase from 'firebase';
const firebaseConfig = { //key hidden here for security reasons
apiKey: apiKey,
authDomain: authDomain,
projectId: projectId,
storageBucket: storageBucket,
messagingSenderId: messagingSenderId,
appId: appId,
measurementId: measurementId
};
const app = !firebase.apps.length
? firebase.initializeApp(firebaseConfig)
: firebase.app();
const db = app.firestore();
const auth = firebase.auth();
export {db, auth};
我的 component.js :
...
import { auth } from '../firebase/firebase';
...
const deleteUser = () => {
const user = auth.currentUser;
const credential = auth.EmailAuthProvider.credential(userEmail,userProvidedPassword);
user.reauthenticateWithCredential(credential).then(() => {
user.delete().then(() => {
auth.signOut();
}).catch((error) => {
console.log(error.message);
});
}).catch((error) => {
console.log(error.message);
});
}
【问题讨论】:
-
您能否编辑您的问题以显示您为 Firebase 添加的依赖项?
-
我解决了这个问题,实际上我什至没有使用“reauthenticateWithCredential”。我只是简单地重新登录然后删除它,它工作得很好。不过还是谢谢你的回复。
标签: reactjs firebase react-native authentication firebase-authentication