-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev-dev' of https://github.com/antonio-pedro99/iiitd_me…
…ntorship into dev-dev
- Loading branch information
Showing
32 changed files
with
482 additions
and
508 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,83 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:iiitd_mentorship/app/data/interfaces/responses.dart'; | ||
import 'package:iiitd_mentorship/app/data/model/auth_status.dart'; | ||
import 'package:iiitd_mentorship/app/data/model/user_auth.dart'; | ||
import 'package:iiitd_mentorship/app/data/repository/auth.dart'; | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
part 'auth_event.dart'; | ||
part 'auth_state.dart'; | ||
|
||
class AuthBloc extends Bloc<AuthEvent, AuthState> { | ||
final AuthRepository _auth = AuthRepository(); | ||
final currentUser = FirebaseAuth.instance.currentUser; | ||
AuthStatus status = AuthStatus.unknown; | ||
|
||
AuthBloc() : super(AuthInitial()) { | ||
on<AuthEvent>((event, emit) async { | ||
on<AuthLogin>((event, emit) async { | ||
emit(AuthLoading()); | ||
final user = (event).user; | ||
final response = await _auth.login(user); | ||
|
||
status = AuthStatus.authenticated; | ||
|
||
emit(_validateResponse(response, status)); | ||
}); | ||
|
||
on<AuthSignUp>((event, emit) async { | ||
emit(AuthLoading()); | ||
final user = (event).user; | ||
final response = await _auth.signup(user); | ||
status = AuthStatus.pending; | ||
|
||
emit(_validateResponse(response, status)); | ||
}); | ||
|
||
on<AuthLogout>((event, emit) async { | ||
emit(AuthLoading()); | ||
switch (event.runtimeType) { | ||
case const (AuthLogin): | ||
final user = (event as AuthLogin).user; | ||
final response = await _auth.login(user); | ||
|
||
emit(_validateResponse(response)); | ||
break; | ||
case const (AuthSignUp): | ||
final user = (event as AuthSignUp).user; | ||
final response = await _auth.signup(user); | ||
|
||
emit(_validateResponse(response)); | ||
break; | ||
case const (AuthLogout): | ||
final response = await _auth.signout(); | ||
|
||
emit(_validateResponse(response)); | ||
break; | ||
case AuthLoginWithGoogle: | ||
final response = await _auth.loginWithGoogle(); | ||
|
||
emit(_validateResponse(response)); | ||
break; | ||
case AuthPhoneSignIn: | ||
final phoneNumber = (event as AuthPhoneSignIn).phoneNumber; | ||
final response = await _auth.phoneSignIn(phoneNumber); | ||
|
||
emit(_validateResponse(response)); | ||
break; | ||
default: | ||
final response = await _auth.signout(); | ||
|
||
status = AuthStatus.unauthenticated; | ||
|
||
emit(_validateResponse(response, status)); | ||
}); | ||
|
||
on<AuthSignUpWithGoogle>((event, emit) async { | ||
emit(AuthLoading()); | ||
final response = await _auth.loginWithGoogle(); | ||
|
||
// check if user is already signed up | ||
final email = (response.data as UserCredential).user!.email!; | ||
|
||
final isSignedUp = await _auth.isAlreadySignedUp(email); | ||
|
||
if (isSignedUp.hasError) { | ||
status = AuthStatus.unknown; | ||
emit(_validateResponse(isSignedUp, status)); | ||
} else { | ||
if (isSignedUp.data as bool) { | ||
status = AuthStatus.authenticated; | ||
emit(_validateResponse(response, status)); | ||
} else { | ||
status = AuthStatus.pending; | ||
emit(_validateResponse(response, status)); | ||
} | ||
} | ||
}); | ||
|
||
on<AuthLoginWithGoogle>((event, emit) async { | ||
emit(AuthLoading()); | ||
final response = await _auth.loginWithGoogle(); | ||
status = AuthStatus.authenticated; | ||
emit(_validateResponse(response, status)); | ||
}); | ||
} | ||
|
||
_validateResponse(FirebaseResponse response) { | ||
_validateResponse(FirebaseResponse response, AuthStatus status) { | ||
if (response.hasError) { | ||
return UnAuthenticated(response.message!); | ||
return UnAuthenticated(response.message!, status: AuthStatus.unknown); | ||
} else { | ||
return Authenticated(response); | ||
return Authenticated(response, status: status); | ||
} | ||
} | ||
} |
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
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 @@ | ||
enum AuthStatus { authenticated, unauthenticated, pending, unknown } |
File renamed without changes.
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
2 changes: 1 addition & 1 deletion
2
lib/app/views/screens/chat/chat_service.dart → lib/app/data/services/chat_service.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
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
Oops, something went wrong.