Luk*_*old 6 firebase firebase-authentication
以下代码有效,如果出现问题,我会收到错误消息。注意,这是 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
}
Run Code Online (Sandbox Code Playgroud)
但是,这里有一个返回的示例error.message:
Firebase: Password should be at least 6 characters (auth/weak-password).
Run Code Online (Sandbox Code Playgroud)
我的问题。有没有办法得到干净的消息回来?我的意思是没有Firebase: 和(auth/weak-password)。
或者我在这里遗漏了什么?我应该有另一种方法来处理 Firebases 错误对象吗?也许我应该error.code为每种情况自己编写一条自定义消息?
如果需要任何其他信息,请告诉我,我将更新问题:)
小智 -1
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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2283 次 |
| 最近记录: |