Skip to content

Commit

Permalink
refactor: rename loginWithOTP to loginWithOTP
Browse files Browse the repository at this point in the history
- it takes `TokenObtainRequest` instead of `email` and `otp`
  • Loading branch information
adar2378 committed Sep 8, 2023
1 parent bbe9129 commit b7aa9dd
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,13 @@ class AuthCubit extends HydratedCubit<AuthState> {
),
);

Future<void> loginWithEmailOTP({
required String email,
required String otp,
/// Login user with OTP. otp should not be empty
Future<void> loginWithOTP({
required TokenObtainRequest tokenObtainRequest,
}) async =>
_authApiChecker(() async {
final tokenResult = (await authApi?.authTokenCreate(
tokenObtainRequest: TokenObtainRequest(
email: email,
otp: otp,
),
tokenObtainRequest: tokenObtainRequest,
))
?.data;
final token = tokenResult?.token;
Expand All @@ -113,12 +110,20 @@ class AuthCubit extends HydratedCubit<AuthState> {
}
}

/// Login user with magic link. magiclink should not be empty
/// It supports only email at the moment.
Future<void> loginWithMagicLink({required String magiclink}) async {
try {
final credentials = utf8
.decode(base64.decode(const Base64Codec().normalize(magiclink)))
.split('/');
await loginWithEmailOTP(email: credentials[0], otp: credentials[1]);

await loginWithOTP(
tokenObtainRequest: TokenObtainRequest(
email: credentials[0],
otp: credentials[1],
),
);
} catch (e) {
rethrow;
}
Expand Down

0 comments on commit b7aa9dd

Please sign in to comment.