0
我正尝试使用REDX传奇实现Google OAuth 2。如何通过REDX传奇处理Google OAuth流程
我有我的传奇观察者监听GOOGLE_AUTH
动作,然后执行googleLogin
function *watchGoogleAuth() {
yield *takeLatest(GOOGLE_AUTH, googleLogin)
}
function *googleLogin() {
const id_token = yield call(GoogleSignIn);
console.log(id_token);
const response = yield call(HttpHelper, 'google_token', 'POST', id_token, null);
console.log(response);
}
为GoogleSignIn
的实现是在apis.js
export function GoogleSignIn() {
const GoogleAuth = window.gapi.auth2.getAuthInstance();
GoogleAuth.signIn({scope: 'profile email'})
.then(
(res) => {
const GoogleUser = GoogleAuth.currentUser.get();
return {
id_token: GoogleUser.getAuthResponse().id_token
};
},
(err) => {
console.log(err)
}
)
}
但传奇似乎并没有等待GoogleSignIn
来完成。只要OAuth同意屏幕弹出,传奇继续执行console.log
而不等待谷歌登录承诺返回实际数据。
有没有更好的方法来处理这种情况?谢谢!
GoogleSignIn函数应该返回promise –