aks*_*nge 5 android firebase firebase-authentication
在我当前的项目中,我正在使用电子邮件 ID 注册用户,然后在用户更新电话号码时在个人资料部分中,我对该电话号码进行身份验证并使用 PhoneAuthCredetials 我正在为同一用户合并两种身份验证方法。
现在真正的痛苦是,我的用户可以使用电话号码或电子邮件 ID 登录,但对于电子邮件 ID,用户必须输入密码,而对于电话号码,则需要 OTP。(我试过了,输入了电话号码和密码signInWithEmailAndPassword()但没有用)
我希望用户使用带有密码的电子邮件或电话登录。Flipkart 的做法。
有什么办法可以管理吗?
使用以下代码创建云函数
const functions = require('firebase-functions');
const firebase = require('firebase');
const admin = require('firebase-admin');
admin.initializeApp();
firebase.initializeApp({
//Add config for web-app here
//Required because Admin SDK doesn't include signInWithEmailAndPassword method
});
exports.signInWithPhoneAndPassword = functions.https.onCall(async (data, context) => {
const phoneNumber = data.phone;
if (phoneNumber === undefined) {
return {'s':400,'m':'Bad argument: no phone number'};
}
const user = await admin.auth().getUserByPhoneNumber(phoneNumber);
const pass = data.password;
try {
await firebase.auth().signInWithEmailAndPassword(user.email, pass);
} catch (e) {
return {'s':400,'m':'Wrong password'};
}
const token = await admin.auth().createCustomToken(user.uid, {'devClaim':true}); //developer claims, optional param
return {'s':200,'t':token};
});
Run Code Online (Sandbox Code Playgroud)
在客户端调用此函数,如果它返回带有"s"==200使用令牌的对象signInWithCustomToken(通过 Firebase 从 Android 调用云函数)
| 归档时间: |
|
| 查看次数: |
2113 次 |
| 最近记录: |