Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase功能用于检查密码是否更改 问题_Firebase_React Native_Google Cloud Firestore_Firebase Authentication_Google Cloud Functions - Fatal编程技术网

Firebase功能用于检查密码是否更改 问题

Firebase功能用于检查密码是否更改 问题,firebase,react-native,google-cloud-firestore,firebase-authentication,google-cloud-functions,Firebase,React Native,Google Cloud Firestore,Firebase Authentication,Google Cloud Functions,我正在使用Firebase工具,如身份验证、函数和Firestore等。我已经用React Native制作了一个应用程序,它有一个登录名。现在我想实现一些逻辑来强制用户更改密码。用户的身份验证通过其uid与Firestore中的用户文档链接 我尝试在用户文档中创建布尔值。布尔值名为changePassword。当我希望用户在水下更改密码时,我将密码更改为随机字符串,并将此布尔值设置为true。当用户登录时,他们的密码被更改,他会自动注销。当用户尝试登录时,会收到一条消息/提示条,询问他们是否想

我正在使用Firebase工具,如身份验证、函数和Firestore等。我已经用React Native制作了一个应用程序,它有一个登录名。现在我想实现一些逻辑来强制用户更改密码。用户的身份验证通过其uid与Firestore中的用户文档链接

我尝试在用户文档中创建布尔值。布尔值名为changePassword。当我希望用户在水下更改密码时,我将密码更改为随机字符串,并将此布尔值设置为true。当用户登录时,他们的密码被更改,他会自动注销。当用户尝试登录时,会收到一条消息/提示条,询问他们是否想通过发送邮件更改密码的按钮来更改密码

这一切都很好,但现在我想在firebase函数中创建一个函数来检查密码是否更改。因此我可以将布尔值changePassword设置为false

因为文档中说只能创建和删除auth,所以最好的做法是什么

代码 自然反应 Main.tsx

if (user && user.emailVerified) {
    const doc = await firestore.collection("users").doc(user.uid).get();
    User.setCurrentUser(doc);
    setAuthenticated(true);
    …
} else {
    setAuthenticated(false);
}
const loginPress = async () => {
    const query = firebase.firestore().collection("users")
        .where('email', ' == ', email.toLowerCase())

    const snapshot = await query.get();
    const formatted = snapshot.docs.map((doc: any) => doc.data());
    const user = formatted[0];

    if (user?.changePassword) {
        props.navigation.navigate('ForgotPassword', { email: email, changePassword: true });
    } else {
        firebase.auth().signInWithEmailAndPassword(email, password).then((result) => {
            ...
        }).catch ((error) => {
        let errorMessage = error.message;
            ...
        });
    }

    Keyboard.dismiss();
}
Login.tsx

if (user && user.emailVerified) {
    const doc = await firestore.collection("users").doc(user.uid).get();
    User.setCurrentUser(doc);
    setAuthenticated(true);
    …
} else {
    setAuthenticated(false);
}
const loginPress = async () => {
    const query = firebase.firestore().collection("users")
        .where('email', ' == ', email.toLowerCase())

    const snapshot = await query.get();
    const formatted = snapshot.docs.map((doc: any) => doc.data());
    const user = formatted[0];

    if (user?.changePassword) {
        props.navigation.navigate('ForgotPassword', { email: email, changePassword: true });
    } else {
        firebase.auth().signInWithEmailAndPassword(email, password).then((result) => {
            ...
        }).catch ((error) => {
        let errorMessage = error.message;
            ...
        });
    }

    Keyboard.dismiss();
}
火基函数 触发器/onUpdate.ts

在函数中,我希望如下所示,但这是不可能的:

  exports.passwordGotChanged = functions.auth.user().onUpdate((snapshot: any) => {
        const before = snapshot.before.data();
        const after = snapshot.after.data();
    
        if (JSON.stringify(before.password) !== JSON.stringify(after.password)) {
            return functions.firestore.document('/users/{after.uid}').set({ changePassword: false }, { merge: true });
        } else {
            return null
        }
    });
附笔
可能这是的副本,但提供的解决方案对我不起作用,可能有新的解决方案

当用户的配置文件更新或密码更改时,无法自动触发功能。没有onUpdate触发器


如果您想在客户端更新其配置文件或更改其密码时在后端执行某些操作,则您的客户端应用程序必须直接调用某种端点。如果您使用的是云函数,则通常使用or函数来实现。没有提供解决方案-这是您必须为自己构建的,以满足您的特定用例。

当用户的配置文件更新或密码更改时,无法自动触发功能。没有onUpdate触发器

如果您想在客户端更新其配置文件或更改其密码时在后端执行某些操作,则您的客户端应用程序必须直接调用某种端点。如果您使用的是云函数,则通常使用or函数来实现。没有提供解决方案-这是您必须为自己构建的东西,以满足您的特定用例