Skip to content

Commit

Permalink
fix: reset user when loading game (#555)
Browse files Browse the repository at this point in the history
* fix: reset user when loading game

* feat: avoid sign out if user unauthenticated
  • Loading branch information
jsgalarraga authored Jun 6, 2024
1 parent 7133427 commit f6b88cf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
8 changes: 7 additions & 1 deletion lib/main_development.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ void main() async {
firebaseAuth: firebaseAuth,
);

// Signing out first to refresh the auth token when reloading the page.
final previousUser = await authenticationRepository.user.first;
if (previousUser != User.unauthenticated) {
await authenticationRepository.signOut();
}
await authenticationRepository.signInAnonymously();
await authenticationRepository.idToken.first;
final newUser = await authenticationRepository.user.first;

final apiClient = ApiClient(
baseUrl: 'https://io-crossword-dev-api-sea6y22h5q-uc.a.run.app',
Expand All @@ -63,7 +69,7 @@ void main() async {
leaderboardRepository: leaderboardRepository,
crosswordRepository: CrosswordRepository(db: firestore),
boardInfoRepository: BoardInfoRepository(firestore: firestore),
user: await authenticationRepository.user.first,
user: newUser,
);
},
),
Expand Down
8 changes: 7 additions & 1 deletion lib/main_production.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ void main() async {
firestore: firestore,
);

// Signing out first to refresh the auth token when reloading the page.
final previousUser = await authenticationRepository.user.first;
if (previousUser != User.unauthenticated) {
await authenticationRepository.signOut();
}
await authenticationRepository.signInAnonymously();
await authenticationRepository.idToken.first;
final newUser = await authenticationRepository.user.first;

final apiClient = ApiClient(
baseUrl: 'https://io-crossword-api-u3emptgwka-uc.a.run.app',
Expand All @@ -53,7 +59,7 @@ void main() async {
leaderboardRepository: leaderboardRepository,
crosswordRepository: CrosswordRepository(db: firestore),
boardInfoRepository: BoardInfoRepository(firestore: firestore),
user: await authenticationRepository.user.first,
user: newUser,
);
},
),
Expand Down
8 changes: 7 additions & 1 deletion lib/main_staging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ void main() async {
firestore: firestore,
);

// Signing out first to refresh the auth token when reloading the page.
final previousUser = await authenticationRepository.user.first;
if (previousUser != User.unauthenticated) {
await authenticationRepository.signOut();
}
await authenticationRepository.signInAnonymously();
await authenticationRepository.idToken.first;
final newUser = await authenticationRepository.user.first;

final apiClient = ApiClient(
baseUrl: 'https://io-crossword-staging-api-sea6y22h5q-uc.a.run.app',
Expand All @@ -63,7 +69,7 @@ void main() async {
leaderboardRepository: leaderboardRepository,
crosswordRepository: CrosswordRepository(db: firestore),
boardInfoRepository: BoardInfoRepository(firestore: firestore),
user: await authenticationRepository.user.first,
user: newUser,
);
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ class AuthenticationRepository {
}
}

/// Sign in the user anonymously.
///
/// If the sign in fails, an [AuthenticationException] is thrown.
/// Sign out the user.
Future<void> signOut() async {
await _firebaseAuth.signOut();

Expand Down

0 comments on commit f6b88cf

Please sign in to comment.