Skip to content

Commit

Permalink
feat: add HydratedAuthCubitBase abstract class
Browse files Browse the repository at this point in the history
- this will alow creating AuthCubit based on different backends or repositories.
  • Loading branch information
adar2378 committed Sep 22, 2023
1 parent 8cb54ae commit 356ba92
Showing 1 changed file with 45 additions and 0 deletions.
@@ -0,0 +1,45 @@
import 'package:djangoflow_auth/djangoflow_auth.dart';
import 'package:djangoflow_openapi/djangoflow_openapi.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';

/// This is the base class for AuthCubit.
/// It allows to create AuthCubit based on any kind of backends.
abstract class HydratedAuthCubitBase extends HydratedCubit<AuthState> {
HydratedAuthCubitBase(AuthState initialState) : super(initialState);

List<SocialLogin> socialLogins = [];

/// Authenticate and request token for user from the Social Auth Provider
/// eg, facebook, google etc.
Future<R?> requestTokenFromSocialProvider<R>(SocialLoginType type);

Future<void> logoutFromSocialProvider(SocialLoginType type);

Future<void> logout();

Future<UserIdentity?> registerOrInviteUser({
required UserIdentityRequest userIdentityRequest,
});

Future<void> requestOTP({required OTPObtainRequest otpObtainRequest});

/// Authenticates the user based on provided credentials (e.g., username+password or email+OTP etc)
/// and logs them in by obtaining and processing a JWT token.
Future<void> obtainTokenAndLogin({
required TokenObtainRequest tokenObtainRequest,
});

/// Login user with magic link. magiclink should not be empty
/// It supports only email at the moment.
Future<void> loginWithMagicLink({required String magiclink});

/// Login user with social provider token data that was retrieved via [requestTokenFromSocialProvider]
/// This will retrieve token from backend and login user
Future<void> loginWithSocialProviderToken(
{required SocialTokenObtainRequest socialTokenObtainRequest});

Future<void> changePassword({
required String id,
required ChangePasswordRequest changePasswordRequest,
});
}

0 comments on commit 356ba92

Please sign in to comment.