一旦我的用户登录成功并且我有一个 Firebase 用户,我想通过调度一个进行异步调用以获取配置文件的操作来检查我的服务器上是否已经创建了一个配置文件。
如果没有返回个人资料,我想将应用导航到个人资料创建页面,否则,加载个人资料页面。
我正在考虑在登录中间件中调度第二个操作,但是在登录中间件中混合配置文件和登录代码似乎很奇怪。
有没有更好的方法或更标准的方法来做我想做的事情?
我没有尝试过任何事情,但我正在考虑在登录中间件中调度第二个操作并从那里导航到所需的页面。
ThunkAction<AppState> logIn = (Store<AppState> store) async {
store.dispatch(UserLoginAction());
try {
final GoogleSignIn _googleSignIn = new GoogleSignIn();
GoogleSignInAccount googleUser = await _googleSignIn.signIn();
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final FirebaseAuth _auth = FirebaseAuth.instance;
final FirebaseUser _fb = await _auth.signInWithGoogle(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
User user = new User(id: _fb.uid, name: _fb.displayName, email: _fb.email, photoUrl: _fb.photoUrl);
store.dispatch(UserLoginSuccessAction(user: user));
store.dispatch(GetProfileAction());
Profile profile = await ProfileService.get().getProfile(_fb.uid);
store.dispatch(GetProfileSuccessAction(profile: profile));
if (profile) {
// Navigate to Profile Page
} else {
// Navigate to Profile Creation Page
}
} catch(error) {
store.dispatch(UserLoginFailAction(error: error));
}
};
编辑:我只是想到了一种比我之前的建议更好的方法。
如果成功登录后我只是将它们导航到个人资料页面怎么办。在配置文件页面的初始位置上,我将发送操作以获取配置文件。Profile 页面将根据中间件和 reducer 完成后是否在 AppState 中初始化 Profile 来呈现不同的内容。
这似乎可以做还是有不同的更好的方法?