Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix authentication issue #54

Merged
merged 1 commit into from
Jan 23, 2024
Merged
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 lib/data/di/service_locator.config.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 14 additions & 8 deletions lib/data/provider/user_state.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:injectable/injectable.dart';
import 'package:projectunity/data/repo/employee_repo.dart';
Expand All @@ -12,24 +13,29 @@ enum UserState { authenticated, unauthenticated, spaceJoined, update }

@LazySingleton()
class UserStateNotifier with ChangeNotifier {

final FirebaseAuth _firebaseAuth;
final UserPreference _userPreference;
final SpaceChangeNotifier _spaceChangeNotifier;
UserState _userState = UserState.unauthenticated;


UserState get state => _userState;

UserStateNotifier(this._userPreference, this._spaceChangeNotifier) {
UserStateNotifier(this._userPreference, this._spaceChangeNotifier,this._firebaseAuth) {
getUserStatus();
}

void getUserStatus() async {
if (_userPreference.getAccount() == null) {
_userState = UserState.unauthenticated;
} else if (_userPreference.getSpace() != null &&
_userPreference.getEmployee() != null) {
_userState = UserState.spaceJoined;
} else if (_userPreference.getAccount() != null) {
_userState = UserState.authenticated;
if (_firebaseAuth.currentUser != null){
Copy link
Collaborator

@cp-pratik-k cp-pratik-k Jan 23, 2024

Choose a reason for hiding this comment

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

what if when firebaseAuth.currentUser is null?

if (_userPreference.getAccount() == null) {
_userState = UserState.unauthenticated;
} else if (_userPreference.getSpace() != null &&
_userPreference.getEmployee() != null) {
_userState = UserState.spaceJoined;
} else if (_userPreference.getAccount() != null) {
_userState = UserState.authenticated;
}
}
}

Expand Down
Loading
Loading