抑制 Firebase 错误登录失败的signInWithEmailAndPassword

2023-12-06

我正在尝试在 NextJS 中使用 Firebase 身份验证来实现登录功能。尽管登录函数的处理程序中的 catch 语句为空,但使用无效登录详细信息调用该函数会向控制台记录错误。如何禁止 Firebase 将此错误记录到控制台?

登录函数处理程序:

const signinWithEmail = async (email, password) => {
    setLoading(true);
    signInWithEmailAndPassword(auth, email, password)
        .then((response) => {
            handleUser(response.user);
            Router.push("/");
        })
        .catch((error) => {
            // Do nothing
        });
};

控制台中的错误(由于暴露的 API 密钥而模糊):

enter image description here


当请求返回错误时,浏览器会显示这些网络错误日志。代码中的 catch 块仍然按预期工作。这可以由用户自己禁用。查看:在控制台中隐藏 Chrome“无法加载资源”消息

请求中可见的 API 密钥应该是公开的,这不是问题。查看:向公众公开 Firebase apiKey 是否安全?

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

抑制 Firebase 错误登录失败的signInWithEmailAndPassword 的相关文章