41 lines
1.3 KiB
Dart
41 lines
1.3 KiB
Dart
import 'package:redux/redux.dart';
|
|
import 'package:invoiceninja/redux/auth/auth_actions.dart';
|
|
import 'package:invoiceninja/redux/auth/auth_state.dart';
|
|
|
|
Reducer<AuthState> authReducer = combineReducers([
|
|
TypedReducer<AuthState, UserLoginLoaded>(userLoginLoadedReducer),
|
|
TypedReducer<AuthState, UserLoginRequest>(userLoginRequestReducer),
|
|
TypedReducer<AuthState, UserLoginSuccess>(userLoginSuccessReducer),
|
|
TypedReducer<AuthState, UserLoginFailure>(userLoginFailureReducer),
|
|
]);
|
|
|
|
AuthState userLoginLoadedReducer(AuthState authState, UserLoginLoaded action) {
|
|
return authState.rebuild((b) => b
|
|
..isInitialized = true
|
|
..url = action.url ?? ''
|
|
..secret = action.secret ?? ''
|
|
..email = action.email ?? ''
|
|
..password = action.password ?? '');
|
|
}
|
|
|
|
AuthState userLoginRequestReducer(
|
|
AuthState authState, UserLoginRequest action) {
|
|
return authState.rebuild((b) => b
|
|
..url = action.url
|
|
..secret = action.secret
|
|
..email = action.email
|
|
..password = action.password);
|
|
}
|
|
|
|
AuthState userLoginSuccessReducer(
|
|
AuthState authState, UserLoginSuccess action) {
|
|
return authState.rebuild((b) => b
|
|
..isAuthenticated = true
|
|
..password = '');
|
|
}
|
|
|
|
AuthState userLoginFailureReducer(
|
|
AuthState authState, UserLoginFailure action) {
|
|
return authState.rebuild((b) => b..error = action.error);
|
|
}
|