Skip to content

Commit

Permalink
feat: implement authentication with twitter
Browse files Browse the repository at this point in the history
- 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
lkmandy committed Feb 28, 2023
1 parent 9010dbc commit f4c911e
Show file tree
Hide file tree
Showing 14 changed files with 800 additions and 45 deletions.
9 changes: 9 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "example://gizmos” -->
<!-- Registered Callback URLs in TwitterApp -->
<data android:scheme="example"
android:host="gizmos" /> <!-- host is option -->
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
Expand Down
18 changes: 18 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<!-- Facebook Configurations Starts -->
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand All @@ -49,6 +50,23 @@
<string>fbapi</string>
<string>fb-messenger-share-api</string>
</array>
<!-- Facebook Configurations Ends -->
<!-- Twitter Configurations Starts -->
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string></string>
<key>CFBundleURLSchemes</key>
<array>
<!-- Registered Callback URLs in TwitterApp -->
<string>example</string>
</array>
</dict>
</array>
<!-- Facebook Configurations Ends -->
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FacebookAuthenticationRepository implements IFacebookRepositoryFacade {
if (user == null) {
return left(const AuthFailure.userNotFound());
}

return right(UserDTO.fromFirebase(user).toDomain());
} on SocketException catch (e) {
return left(AuthFailure.fromErrorMessage(e.message));
Expand Down
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))),
);
}
}
Loading

0 comments on commit f4c911e

Please sign in to comment.