Skip to content

Commit

Permalink
Fix apple sign in
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sneha-s committed Apr 5, 2024
1 parent 48b630f commit 2b07a7e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
1 change: 0 additions & 1 deletion lib/data/core/exception/error_const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const String alreadyLeaveAppliedError = 'already-applied';
const String somethingWentWrongError = 'something-went-wrong';
const String appleSigninError = 'apple-signin-error';


//Exception: when user don't provide all the required information in fields,
const String provideRequiredInformation = 'provide-required-information';

Expand Down
4 changes: 2 additions & 2 deletions lib/data/services/account_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ class AccountService {
if (userData != null) {
await _setUserSession(authData.uid);
return userData;
} else if(authData.email != null ){
} else if (authData.email != null) {
final user = Account(
uid: authData.uid,
email: authData.email!,
name: authData.displayName);
await _accountsDb.doc(authData.uid).set(user);
await _setUserSession(authData.uid);

return user;
}
return null;
}

Future<void> _setUserSession(String uid) async {
Expand Down
12 changes: 6 additions & 6 deletions lib/ui/sign_in/bloc/sign_in_view_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SignInBloc extends Bloc<SignInEvent, SignInState> {
firebase_auth.User? authUser = await _authService.signInWithApple();
if (authUser != null) {
final Account? user = await _accountService.getAppleUser(authUser);
if(user == null) {
if (user == null) {
emit(state.copyWith(
appleSignInLoading: false, error: appleSigninError));
return;
Expand All @@ -62,13 +62,13 @@ class SignInBloc extends Bloc<SignInEvent, SignInState> {
} else {
emit(state.copyWith(appleSignInLoading: false));
}
} catch(e,stack) {
if(e is FirebaseAuthException && e.code == 'canceled') {
emit(state.copyWith(
appleSignInLoading: false));
} catch (e, stack) {
if (e is FirebaseAuthException && e.code == 'canceled') {
emit(state.copyWith(appleSignInLoading: false));
return;
}
FirebaseCrashlytics.instance.recordError(e, stack,reason: 'Apple Sign In Error');
FirebaseCrashlytics.instance
.recordError(e, stack, reason: 'Apple Sign In Error');
emit(state.copyWith(
appleSignInLoading: false, error: somethingWentWrongError));
}
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/sign_in/sign_in_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class SignInScreenState extends State<SignInScreen> {
listener: (context, state) {
if (state.error != null) {
if (state.error == appleSigninError) {
showSnackBar(context: context, msg: context.l10n.apple_sign_in_error_message);
showSnackBar(
context: context,
msg: context.l10n.apple_sign_in_error_message);
} else {
showSnackBar(context: context, error: state.error);
}
Expand Down

0 comments on commit 2b07a7e

Please sign in to comment.