HarmonyOS鸿蒙Next中已登录成功,但是调用getCurrentUser返回的user是null
HarmonyOS鸿蒙Next中已登录成功,但是调用getCurrentUser返回的user是null
agconnect.instance().configInstance(agConnectConfig);
// login const phoneNumberLogin = (props, callback) => { const { countryCode = “86”, phoneNumber, password } = props; const credential = agconnect.auth.PhoneAuthProvider.credentialWithPassword( countryCode, phoneNumber, password ); agconnect .auth() .signIn(credential) .then((user) => { //登录成功 console.log(“utils/AGCAuth.js => phoneNumberLogin() success:”, user); callback(AUTH_CODE.Successed, user); }) .catch((error) => { //登录失败 console.log(“utils/AGCAuth.js => phoneNumberLogin() error:”, error); callback(AUTH_CODE.Error, error); }); };
// get current user const getCurrentUser = (callback) => { agconnect .auth() .getCurrentUser() .then((user) => { //获取用户成功 //此处获取user一直是null,刚登录成功,再调用这个function,返回的user也是null console.log(“utils/AGCAuth.js => getCurrentUser() success:”, user); if (!!user) { callback(AUTH_CODE.Successed, user); } else { callback(AUTH_CODE.Unauthorized, user); } }) .catch((error) => { //获取用户失败 console.log(“utils/AGCAuth.js => getCurrentUser() error:”, error); callback(AUTH_CODE.Error, error); }); };
如代码所示,web端登录认证。getCurrentUser then 处获取user一直是null,刚登录成功,再调用这个function,返回的user也是null。
另外,发帖插入代码的 textarea 好小......
更多关于HarmonyOS鸿蒙Next中已登录成功,但是调用getCurrentUser返回的user是null的实战教程也可以访问 https://www.itying.com/category-93-b0.html