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

Allow easy access of user object in auth repo. #1206

Merged
merged 2 commits into from
Oct 24, 2024
Merged
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
13 changes: 10 additions & 3 deletions lib/features/family/features/auth/data/family_auth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ abstract class FamilyAuthRepository {
Stream<UserExt?> authenticatedUserStream();

Session getStoredSession();

UserExt? getCurrentUser();
}

class FamilyAuthRepositoryImpl implements FamilyAuthRepository {
Expand Down Expand Up @@ -141,7 +143,7 @@ class FamilyAuthRepositoryImpl implements FamilyAuthRepository {
final userExt = UserExt.fromJson(response);
await _storeUserExt(userExt);
await _setUserPropsForExternalServices(userExt);
_authenticatedUserStream.add(userExt);
_updateAuthenticatedUserStream(userExt);
return userExt;
} catch (e, s) {
LoggingInfo.instance.error(
Expand All @@ -157,6 +159,7 @@ class FamilyAuthRepositoryImpl implements FamilyAuthRepository {
UserExt.tag,
jsonEncode(userExt.toJson()),
);
_updateAuthenticatedUserStream(userExt);
}

@override
Expand Down Expand Up @@ -223,7 +226,7 @@ class FamilyAuthRepositoryImpl implements FamilyAuthRepository {
// _prefs.clear();
final sessionString = _prefs.getString(Session.tag);

updateAuthenticatedUserStream(null);
_updateAuthenticatedUserStream(null);

// If the data is already gone, just continue :)
if (sessionString == null) {
Expand Down Expand Up @@ -317,7 +320,11 @@ class FamilyAuthRepositoryImpl implements FamilyAuthRepository {
);
}

void updateAuthenticatedUserStream(UserExt? userExt) {
void _updateAuthenticatedUserStream(UserExt? userExt) {
_userExt = userExt;
_authenticatedUserStream.add(userExt);
}

@override
UserExt? getCurrentUser() => _userExt;
}