validateEmailLink method
Implementation
@override
Future<Either<AuthServiceEmailLinkFailure, Unit>> validateEmailLink(String link,
{String? email}) async {
String? storedEmail;
var uriLink = Uri.parse(link);
if (uriLink.host != 'localhost' && (!_fbAuth.isSignInWithEmailLink(link))) {
logd('isSignInWithEmailLink failed');
return left(AuthServiceEmailLinkFailure.invalidLink);
} else {
// Get the email from storage if we can
// if (email == null) {
// storedEmail = GetStorage().read(Constants.boxKeyUserSignInWithLinkEmail);
// } else {
// storedEmail = email;
// }
// If email is still null, we need to ask the user
// if (storedEmail == null) {
// return left(AuthServiceEmailLinkFailure.noEmailRemembered());
// }
//TODO: sure we want to rely on this email being passed?
storedEmail = email;
logd('storedEmail: $storedEmail');
logd('link: $link');
try {
// Do the signin
var signInResult = await _fbAuth.signInWithEmailLink(
email: storedEmail!,
emailLink: link,
);
assert(signInResult.user != null);
currentFbUserCredentials = signInResult;
// Don't need the temp storage anymore
// GetStorage().remove(Constants.boxKeyUserSignInWithLinkEmail);
// Create, Get the firebase user and return
//TODO: broken due to separating private data
// var dbCreateResult = await Get.find<UserRepoInt>().createUserIfNotExist(User(
// id: currentFbUserCredentials!.user!.uid,
//email: currentFbUserCredentials!.user!.email!,
// ));
// Determine outcome
// Either<AuthServiceEmailLinkFailure, Unit> returnVal = dbCreateResult.fold(
// (failure) {
// return failure.maybeWhen(
// orElse: () => left(AuthServiceEmailLinkFailure.databaseError()),
// );
// },
// (success) {
// currentUser.value = success;
// return right(unit);
// },
// );
// Finally return
// return returnVal;
//TODO: make sure this doesn't return before getting the user info loaded
await isLoggedInAsync();
// final response = await http.get(Uri.parse(url), headers: {
// 'Authorization': 'Bearer $token',
// });
return right(unit);
} on fb_auth.FirebaseAuthException catch (e) {
loge(e);
switch (e.code) {
case 'invalid-action-code':
return left(AuthServiceEmailLinkFailure.invalidCode);
case 'invalid-email':
return left(AuthServiceEmailLinkFailure.invalidEmail);
case 'expired-action-code':
return left(AuthServiceEmailLinkFailure.expiredCode);
case 'user-disabled':
return left(AuthServiceEmailLinkFailure.userDisabled);
default:
return left(AuthServiceEmailLinkFailure.unexpected);
}
} catch (e) {
loge(e);
return left(AuthServiceEmailLinkFailure.unexpected);
}
}
}