-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement authentication with twitter
- Add twitter authentication configurations on android and ios - Implement the overall twitter authentication logic - Attach the twitter authentication logic to the user interface
- Loading branch information
Showing
14 changed files
with
800 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...tication_with_twitter/application/twitter_authentication/twitter_authentication_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:dartz/dartz.dart'; | ||
import 'package:fpb/authentication_with_twitter/domain/i_twitter_repository_facade.dart'; | ||
import 'package:fpb/core/domain/user.dart'; | ||
import 'package:fpb/core/failures/auth_failure.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
part 'twitter_authentication_event.dart'; | ||
part 'twitter_authentication_state.dart'; | ||
part 'twitter_authentication_bloc.freezed.dart'; | ||
|
||
class TwitterAuthenticationBloc | ||
extends Bloc<TwitterAuthenticationEvent, TwitterAuthenticationState> { | ||
TwitterAuthenticationBloc({required this.authenticationRepository}) | ||
: super(TwitterAuthenticationState.initial()) { | ||
on<TwitterSignIn>(_onTwitterSignInPressed); | ||
on<TwitterSignOut>(_onTwitterSignOutPressed); | ||
} | ||
|
||
final ITwitterRepositoryFacade authenticationRepository; | ||
|
||
Future<void> _onTwitterSignInPressed( | ||
TwitterSignIn event, | ||
Emitter<TwitterAuthenticationState> emit, | ||
) async { | ||
emit(state.copyWith(isLoading: true)); | ||
final failureOrUser = await authenticationRepository.signInWithTwitter(); | ||
failureOrUser.fold( | ||
(failure) => emit(TwitterAuthenticationState( | ||
failureOrUser: left(failure), isLoading: false)), | ||
(user) => emit(TwitterAuthenticationState( | ||
isLoading: false, failureOrUser: right(user))), | ||
); | ||
} | ||
|
||
Future<void> _onTwitterSignOutPressed( | ||
TwitterSignOut event, | ||
Emitter<TwitterAuthenticationState> emit, | ||
) async { | ||
emit(state.copyWith(isLoading: true)); | ||
final failureOrUnit = await authenticationRepository.signOut(); | ||
failureOrUnit.fold( | ||
(failure) => emit(TwitterAuthenticationState( | ||
failureOrUser: left(failure), isLoading: false)), | ||
(unit) => emit(TwitterAuthenticationState( | ||
isLoading: false, failureOrUser: right(User.empty))), | ||
); | ||
} | ||
} |
Oops, something went wrong.