Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
classpath 'com.google.gms:google-services:4.3.15'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.4'
}
}

Expand Down
3 changes: 1 addition & 2 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
70 changes: 35 additions & 35 deletions lib/application/auth/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import 'dart:io';

import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:equatable/equatable.dart';
import 'package:injectable/injectable.dart';

import '../../domain/auth/auth_failures.dart';
import '../../domain/auth/auth_success.dart';
import '../../domain/auth/auth_success.dart' as $auth_success;
import '../../domain/auth/i_auth_repository.dart';
import '../../domain/user/i_avatar_repository.dart';
import '../../domain/user/i_user_repository.dart';
import '../../domain/user/user.dart';

part 'auth_bloc.freezed.dart';
part 'auth_event.dart';
part 'auth_state.dart';

Expand All @@ -24,7 +23,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {

Credential? _credential;
String? _phone;
StreamSubscription<Either<AuthFailure, AuthSuccess>>?
StreamSubscription<Either<AuthFailure, $auth_success.AuthSuccess>>?
_verifyStreamSubscription;
StreamSubscription? _authenticationStateSubscription;

Expand All @@ -34,21 +33,25 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
) : super(const AuthState.initial()) {
on<AuthEvent>(
(event, emit) async {
await event.map(
initial: (event) async => await _mapObserveUserToState(emit, event),
verifyPhone: (event) async =>
await _mapVerifyPhoneToState(emit, event),
signInWithPhone: (event) async =>
await _mapSignInWithPhoneToState(emit, event),
updated: (event) async => await _mapUpdatedToState(emit, event),
reset: (event) async => await _mapResetToState(emit, event),
authCheckRequested: (event) async =>
await _mapAuthCheckRequestToState(emit, event),
signedOut: (event) async => await _mapSignOutToState(emit, event),
updateProfilePhoto: (event) async =>
await _mapUpdateProfilePhotoToState(emit, event),
resendCode: (event) async => await _mapResendCodeToState(emit, event),
);
if (event is _InitialEvent) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This screams of Switch.

Maybe we can add a const to each event (parent class and need to override), eg.
const eventName = "SIGN_IN_WITH_PHONE";

await _mapObserveUserToState(emit, event);
} else if (event is _VerifyPhone) {
await _mapVerifyPhoneToState(emit, event);
} else if (event is _SignInWithPhone) {
await _mapSignInWithPhoneToState(emit, event);
} else if (event is _Updated) {
await _mapUpdatedToState(emit, event);
} else if (event is _Reset) {
await _mapResetToState(emit, event);
} else if (event is _AuthCheckRequested) {
await _mapAuthCheckRequestToState(emit, event);
} else if (event is _SignedOut) {
await _mapSignOutToState(emit, event);
} else if (event is _UpdateProfilePhoto) {
await _mapUpdateProfilePhotoToState(emit, event);
} else if (event is _ResendCode) {
await _mapResendCodeToState(emit, event);
}
},
);
}
Expand Down Expand Up @@ -135,22 +138,19 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
event.failureOrCredential.fold(
(failure) => AuthState.authError(failure),
(r) {
return r.map(
codeSent: (event) {
_credential = event.credential;
return const AuthState.smsCodeSent();
},
codeRetrievalTimedOut: (event) {
_credential = event.credential;
return const AuthState.codeRetrievalTimedOut();
},
verificationCompleted: (event) {
_credential = event.credential;
return AuthState.verificationCompleted(
_credential?.smsCode ?? '',
);
},
);
_credential = r.credential;

if (r is $auth_success.SmsCodeSent) {
return const AuthState.smsCodeSent();
} else if (r is $auth_success.CodeRetrievalTimedOut) {
return const AuthState.codeRetrievalTimedOut();
} else if (r is $auth_success.VerificationCompleted) {
return AuthState.verificationCompleted(
_credential?.smsCode ?? '',
);
}

throw Exception();
},
),
);
Expand Down
68 changes: 65 additions & 3 deletions lib/application/auth/auth_event.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
part of 'auth_bloc.dart';

@freezed
class AuthEvent with _$AuthEvent {
abstract class AuthEvent extends Equatable {
const AuthEvent();

const factory AuthEvent.initial() = _InitialEvent;

const factory AuthEvent.verifyPhone(String phoneNumber) = _VerifyPhone;

const factory AuthEvent.updated(
Either<AuthFailure, AuthSuccess> failureOrCredential,
Either<AuthFailure, $auth_success.AuthSuccess> failureOrCredential,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't it just be AuthSuccess

) = _Updated;

const factory AuthEvent.signInWithPhone(String smsCode) = _SignInWithPhone;
Expand All @@ -23,4 +24,65 @@ class AuthEvent with _$AuthEvent {

/// Sign out
const factory AuthEvent.signedOut() = _SignedOut;

@override
List<Object?> get props => [];
}

class _InitialEvent extends AuthEvent {
const _InitialEvent();
}

class _VerifyPhone extends AuthEvent {
final String phoneNumber;

const _VerifyPhone(this.phoneNumber);

@override
List<Object?> get props => [phoneNumber];
}

class _Updated extends AuthEvent {
final Either<AuthFailure, $auth_success.AuthSuccess> failureOrCredential;

const _Updated(this.failureOrCredential);

@override
List<Object?> get props => [failureOrCredential];
}

class _SignInWithPhone extends AuthEvent {
final String smsCode;

const _SignInWithPhone(this.smsCode);

@override
List<Object?> get props => [smsCode];
}

class _ResendCode extends AuthEvent {
const _ResendCode();
}

class _UpdateProfilePhoto extends AuthEvent {
final File photo;

const _UpdateProfilePhoto(this.photo);

@override
List<Object?> get props => [photo];
}

class _Reset extends AuthEvent {
const _Reset();
}

/// Request for current auth state
class _AuthCheckRequested extends AuthEvent {
const _AuthCheckRequested();
}

/// Sign out
class _SignedOut extends AuthEvent {
const _SignedOut();
}
114 changes: 106 additions & 8 deletions lib/application/auth/auth_state.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
part of 'auth_bloc.dart';

@freezed
class AuthState with _$AuthState {
abstract class AuthState extends Equatable {
const AuthState();

/// No authentication ongoing
const factory AuthState.initial() = _Initial;

/// Authentication has been started, waiting for backend to respond
const factory AuthState.signingInUser() = SigningInUser;

/// SMS Code has been sent, wait for autocomplete or user to enter code
const factory AuthState.smsCodeSent() = _SmsCodeSent;
const factory AuthState.smsCodeSent() = SmsCodeSent;

/// SMS Code verification has been completed, sign in user with credentials
const factory AuthState.verificationCompleted(String smsCode) =
_VerificationCompleted;
VerificationCompleted;

/// SMS Code autocomplete has timed out, allow user to resend code
const factory AuthState.codeRetrievalTimedOut() = _CodeRetrievalTimedOut;

/// An error has occurred during authentication
const factory AuthState.authError(AuthFailure failure) = _AuthError;
const factory AuthState.authError(AuthFailure failure) = AuthError;

/// Authentication may be completed with verification code
const factory AuthState.awaitingVerification() = AwaitingVerification;
Expand All @@ -28,7 +29,7 @@ class AuthState with _$AuthState {
const factory AuthState.verifying(String smsCode) = _Verifying;

/// Authentication has been completed
const factory AuthState.loggedIn({required bool isNewUser}) = _LoggedIn;
const factory AuthState.loggedIn({required bool isNewUser}) = LoggedIn;

/// Code is being resent
const factory AuthState.awaitingCodeResend() = AwaitingCodeResend;
Expand All @@ -37,10 +38,107 @@ class AuthState with _$AuthState {
const factory AuthState.awaitingPhotoUpdate() = AwaitingProfilePhotoUpdate;

/// Profile photo update done
const factory AuthState.photoUpdateDone() = _ProfilePhotoUpdateDone;
const factory AuthState.photoUpdateDone() = ProfilePhotoUpdateDone;

/// Splash Auth states
const factory AuthState.authenticated(User user) = _Authenticated;
const factory AuthState.authenticated(User user) = Authenticated;

const factory AuthState.unauthenticated() = _UnAuthenticated;

@override
List<Object?> get props => [];
}

/// No authentication ongoing
class _Initial extends AuthState {
const _Initial();
}

/// Authentication has been started, waiting for backend to respond
class SigningInUser extends AuthState {
const SigningInUser();
}

/// SMS Code has been sent, wait for autocomplete or user to enter code
class SmsCodeSent extends AuthState {
const SmsCodeSent();
}

/// SMS Code verification has been completed, sign in user with credentials
class VerificationCompleted extends AuthState {
final String smsCode;

const VerificationCompleted(this.smsCode);

@override
List<Object?> get props => [smsCode];
}

/// SMS Code autocomplete has timed out, allow user to resend code
class _CodeRetrievalTimedOut extends AuthState {
const _CodeRetrievalTimedOut();
}

/// An error has occurred during authentication
class AuthError extends AuthState {
final AuthFailure failure;

const AuthError(this.failure);

@override
List<Object?> get props => [failure];
}

/// Authentication may be completed with verification code
class AwaitingVerification extends AuthState {
const AwaitingVerification();
}

/// Authentication will be completed, waiting for backend to respond to verification
class _Verifying extends AuthState {
final String smsCode;

const _Verifying(this.smsCode);

@override
List<Object?> get props => [smsCode];
}

/// Authentication has been completed
class LoggedIn extends AuthState {
final bool isNewUser;

const LoggedIn({required this.isNewUser});

@override
List<Object?> get props => [isNewUser];
}

/// Code is being resent
class AwaitingCodeResend extends AuthState {
const AwaitingCodeResend();
}

/// Profile Photo is being updated
class AwaitingProfilePhotoUpdate extends AuthState {
const AwaitingProfilePhotoUpdate();
}

/// Profile photo update done
class ProfilePhotoUpdateDone extends AuthState {
const ProfilePhotoUpdateDone();
}

/// Splash Auth states
class Authenticated extends AuthState {
final User user;

const Authenticated(this.user);

@override
List<Object?> get props => [user];
}

class _UnAuthenticated extends AuthState {
const _UnAuthenticated();
}
Loading