verifyEmailCode method
Implementation
Future<void> verifyEmailCode({
String? userId,
String? username,
String? email,
required String code,
required LoginType loginType,
}) async {
if (userId == null && username == null && email == null) {
throw Exception(
"missing one required identifier: userId, optionalId or email");
} else if (code == "") {
throw Exception("email verification code is empty");
}
String cloudToken = await _authorize.getAccessToken();
HeraRequest req = HeraRequest();
User user = User();
user.id = userId ?? "";
user.username = username ?? "";
user.email = email ?? "";
user.emailVerificationCode = code;
user.phoneVerificationCode = code;
req.cloudToken = cloudToken;
req.user = user;
req.namespace = namespace;
try {
if (loginType == LoginType.EMAIL_PASSWORD ||
loginType == LoginType.EMAIL_VERIFICATION_CODE) {
await grpcUserClient.verifyEmail(req);
} else if (loginType == LoginType.PHONE_PASSWORD ||
loginType == LoginType.PHONE_VERIFICATION_CODE) {
await grpcUserClient.verifyPhone(req);
} else {
throw Exception("invalid login type");
}
} catch (e) {
if (debug == true) print("could verify email with err: " + e.toString());
rethrow;
}
}