Skip to content

Commit 56f77cd

Browse files
committed
feat: Add anonymous auth status
- Added anonymous status - Updated router logic - Updated app bloc logic
1 parent e570a0e commit 56f77cd

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

lib/app/bloc/app_bloc.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ class AppBloc extends Bloc<AppEvent, AppState> {
5050
AppUserChanged event,
5151
Emitter<AppState> emit,
5252
) {
53-
if (event.user.isAnonymous) {
54-
emit(state.copyWith(status: AppStatus.unauthenticated));
55-
} else {
56-
emit(state.copyWith(status: AppStatus.authenticated));
53+
switch (event.user.authenticationStatus) {
54+
case AuthenticationStatus.unauthenticated:
55+
emit(state.copyWith(status: AppStatus.unauthenticated));
56+
break;
57+
case AuthenticationStatus.anonymous:
58+
emit(state.copyWith(status: AppStatus.anonymous));
59+
break;
60+
case AuthenticationStatus.authenticated:
61+
emit(state.copyWith(status: AppStatus.authenticated));
62+
break;
5763
}
5864
}
5965

lib/app/bloc/app_state.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
part of 'app_bloc.dart';
22

3-
enum AppStatus { authenticated, unauthenticated }
3+
/// Represents the application's authentication status.
4+
enum AppStatus {
5+
/// The user is authenticated.
6+
authenticated,
7+
8+
/// The user is not authenticated.
9+
unauthenticated,
10+
11+
/// The user is anonymous (signed in using an anonymous provider).
12+
anonymous,
13+
}
414

515
class AppState extends Equatable {
616
const AppState({

lib/router/router.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ final appRouter = GoRouter(
1515
const authenticationPath = Routes.authentication;
1616
const headlinesFeedPath = Routes.headlinesFeed;
1717

18-
// If the user is authenticated, redirect to the headlines feed
18+
// If the user is authenticated or anonymous, redirect to the headlines feed
1919
// unless they are already on a route within the headlines feed.
20-
if (appStatus == AppStatus.authenticated) {
20+
if (appStatus == AppStatus.authenticated ||
21+
appStatus == AppStatus.anonymous) {
2122
if (!state.matchedLocation.startsWith(headlinesFeedPath)) {
2223
return headlinesFeedPath;
2324
}
2425
}
2526
// If the user is not authenticated, redirect to the authentication page
2627
// unless they are already on a route within the authentication section.
27-
else {
28+
else if (appStatus == AppStatus.unauthenticated) {
2829
if (!state.matchedLocation.startsWith(authenticationPath)) {
2930
return authenticationPath;
3031
}

pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ packages:
370370
description:
371371
path: "."
372372
ref: main
373-
resolved-ref: d527953e11fa19f2fadae381488682c574c83831
373+
resolved-ref: bfad276e63a6d703a635cf743bcf88abcb1d48e0
374374
url: "https://github.com/headlines-toolkit/ht-authentication-client.git"
375375
source: git
376376
version: "0.0.0"
@@ -379,7 +379,7 @@ packages:
379379
description:
380380
path: "."
381381
ref: main
382-
resolved-ref: ca9b62306f54c3e57631cd46c91b1b4426e0a7c3
382+
resolved-ref: "2c711c1ac23f4f3c866bea9d1152b83c188cf7fa"
383383
url: "https://github.com/headlines-toolkit/ht-authentication-firebase.git"
384384
source: git
385385
version: "0.0.0"

0 commit comments

Comments
 (0)