-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* using different segment * WIP * WIP * rename jobs events * update successCallback on loginRequestCall * minor * minor * revert verify auto login * Wip * add auto routes generator & fix login flow * last fixes * fixed Co-authored-by: Tal Beja <bejavu@gmail.com>
- Loading branch information
Showing
53 changed files
with
756 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:fusecash/models/app_state.dart'; | ||
import 'package:fusecash/redux/actions/cash_wallet_actions.dart'; | ||
import 'package:fusecash/redux/actions/error_actions.dart'; | ||
import 'package:fusecash/redux/actions/user_actions.dart'; | ||
import 'package:fusecash/redux/state/store.dart'; | ||
import 'package:fusecash/screens/routes.gr.dart'; | ||
import 'package:fusecash/services.dart'; | ||
import 'package:fusecash/utils/phone.dart'; | ||
import 'package:redux/redux.dart'; | ||
import 'package:firebase_auth_platform_interface/firebase_auth_platform_interface.dart'; | ||
|
||
List<Middleware<AppState>> createAuthMiddleware() { | ||
final loginRequest = _createLoginRequestMiddleware(); | ||
final verifyRequest = _createVerifyPhoneNumberMiddleware(); | ||
|
||
return [ | ||
TypedMiddleware<AppState, LoginRequest>(loginRequest), | ||
TypedMiddleware<AppState, VerifyRequest>(verifyRequest), | ||
]; | ||
} | ||
|
||
Middleware<AppState> _createLoginRequestMiddleware() { | ||
return (Store store, action, NextDispatcher next) async { | ||
final logger = await AppFactory().getLogger('action'); | ||
|
||
if (action is LoginRequest) { | ||
try { | ||
String phone = formatPhoneNumber(action.phoneNumber, action.countryCode); | ||
await firebaseAuth.verifyPhoneNumber( | ||
phoneNumber: phone, | ||
codeAutoRetrievalTimeout: action.codeAutoRetrievalTimeout, | ||
codeSent: action.codeSent, | ||
timeout: Duration(minutes: 2), | ||
verificationCompleted: action.verificationCompleted, | ||
verificationFailed: action.verificationFailed | ||
); | ||
store.dispatch(new LoginRequestSuccess(action.countryCode, action.phoneNumber, "", "")); | ||
} | ||
catch (e, s) { | ||
logger.severe('ERROR - LoginRequest $e'); | ||
await AppFactory().reportError(e, s); | ||
store.dispatch(new ErrorAction(e)); | ||
store.dispatch(segmentTrackCall("ERROR in LoginRequest", properties: new Map.from({ "error": e.toString() }))); | ||
} | ||
} | ||
next(action); | ||
}; | ||
} | ||
|
||
Middleware<AppState> _createVerifyPhoneNumberMiddleware() { | ||
return (Store store, action, NextDispatcher next) async { | ||
final logger = await AppFactory().getLogger('action'); | ||
if (action is VerifyRequest) { | ||
try { | ||
PhoneAuthCredential credential = store.state.userState.credentials; | ||
if (credential == null) { | ||
credential = PhoneAuthProvider.getCredential( | ||
verificationId: action.verificationId, | ||
smsCode: action.verificationCode, | ||
); | ||
} | ||
final FirebaseUser user = (await firebaseAuth.signInWithCredential(credential)).user; | ||
final FirebaseUser currentUser = await firebaseAuth.currentUser(); | ||
assert(user.uid == currentUser.uid); | ||
String accountAddress = store.state.userState.accountAddress; | ||
IdTokenResult token = await user.getIdToken(); | ||
String jwtToken = await api.login(token.token, accountAddress); | ||
store.dispatch(new LoginVerifySuccess(jwtToken)); | ||
Router.navigator.pushReplacementNamed(Router.userNameScreen); | ||
} | ||
catch (e, s) { | ||
logger.severe('ERROR - Verification failed $e'); | ||
await AppFactory().reportError(e, s); | ||
store.dispatch(new ErrorAction(e)); | ||
store.dispatch(segmentTrackCall("ERROR in VerifyRequest", properties: new Map.from({ "error": e.toString() }))); | ||
} | ||
} | ||
next(action); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.