createMiddleware method
Middleware<T>
createMiddleware()
Implementation
Middleware<T> createMiddleware() {
return (Store<T> store, dynamic action, NextDispatcher next) {
// print(store.state.accountKitState.prefix);
/// Token is cleared after a signout
if ((action is SignOutAction)) {
store.dispatch(ClearTokenNetworkAction());
}
if ((action is ImpersonateSuccessAction)) {
store.dispatch(GetUserAction());
}
/// Provides path to the request ONLY for accountkit actions
if (action is RequestAction) {
RequestAction castAction = action;
if (castAction.dispatcherKey == constDispatcherKey) {
castAction.path =
"${store.state.accountKitState.prefix}${castAction.path}";
}
return next(castAction);
}
/// Save the access token as a biometric way to sign in
if ((action is CreateAccessTokenSuccessAction)) {
store.dispatch(SetBiometricAccessToken(action.accessToken));
store
.dispatch(SetBiometricTokenNetworkAction(action.accessToken.token));
}
next(action);
};
}