firebase - 如何使用 firebase 9 显示错误消息
问题描述
以下代码有效,如果出现问题,我会收到错误消息。注意,这是 Vue 代码。因此.value
import { getAuth, createUserWithEmailAndPassword } from 'firebase/auth'
const register = async () => {
loading.value = true
let response
try {
const auth = getAuth()
response = await createUserWithEmailAndPassword(
auth,
form.value.email,
form.value.password
)
} catch (err) {
console.log(err.message)
}
loading.value = false
return response
}
但是,这是返回的示例error.message
:
Firebase: Password should be at least 6 characters (auth/weak-password).
我的问题。有没有办法让一个干净的消息回来?我的意思是没有Firebase:
and (auth/weak-password)
。
或者我在这里错过了什么?我应该用另一种方法来处理 Firebase 错误对象吗?也许我应该error.code
为每个场景自己编写自定义消息?
让我知道是否需要任何其他信息,我会更新问题:)
解决方案
import { getAuth, createUserWithEmailAndPassword } from 'firebase/auth'
const register = async () => {
loading.value = true
let response
try {
if(form.value.password.length <= 6 ){
return "Password should be at least 6 characters (auth/weak-password)"
}
const auth = getAuth()
response = await createUserWithEmailAndPassword(
auth,
form.value.email,
form.value.password
)
} catch (err) {
console.log(err.message)
}
loading.value = false
return response
}
推荐阅读
- python-3.x - 将单个值的 PeriodIndex 应用于 pandas 数据帧的所有行
- php - Laravel 路由视图缓存
- r - 我的包函数修改版找不到包的其他内部函数
- debugging - Jenkins 未在 AWS ec2 t2 大型实例中运行
- javascript - JQuery datepicker不保存选定的日期
- svg - 多个对象上的一个渐变
- vue.js - Vue Js 立即添加事件监听器触发
- sql - 使用 ts_vector 列进行文本搜索
- python - 使用 Python 在 JIRA 中使用受让人、观察者和附件创建新问题
- c# - WPF:如何为 ListView 创建自定义视图模式