1
1
import 'dart:async' ;
2
2
3
+ import 'package:auth_repository/auth_repository.dart' ;
3
4
import 'package:bloc/bloc.dart' ;
4
- import 'package:equatable/equatable.dart' ;
5
- import 'package:ht_auth_repository/ht_auth_repository.dart' ;
6
- import 'package:ht_shared/ht_shared.dart'
5
+ import 'package:core/core.dart'
7
6
show
8
7
AuthenticationException,
9
8
ForbiddenException,
10
- HtHttpException ,
9
+ HttpException ,
11
10
InvalidInputException,
12
11
NetworkException,
13
12
NotFoundException,
@@ -16,6 +15,7 @@ import 'package:ht_shared/ht_shared.dart'
16
15
UnauthorizedException,
17
16
UnknownException,
18
17
User;
18
+ import 'package:equatable/equatable.dart' ;
19
19
20
20
part 'authentication_event.dart' ;
21
21
part 'authentication_state.dart' ;
@@ -26,7 +26,7 @@ part 'authentication_state.dart';
26
26
class AuthenticationBloc
27
27
extends Bloc <AuthenticationEvent , AuthenticationState > {
28
28
/// {@macro authentication_bloc}
29
- AuthenticationBloc ({required HtAuthRepository authenticationRepository})
29
+ AuthenticationBloc ({required AuthRepository authenticationRepository})
30
30
: _authenticationRepository = authenticationRepository,
31
31
super (const AuthenticationState ()) {
32
32
// Listen to authentication state changes from the repository
@@ -42,7 +42,7 @@ class AuthenticationBloc
42
42
on < AuthenticationSignOutRequested > (_onAuthenticationSignOutRequested);
43
43
}
44
44
45
- final HtAuthRepository _authenticationRepository;
45
+ final AuthRepository _authenticationRepository;
46
46
late final StreamSubscription <User ?> _userAuthSubscription;
47
47
48
48
/// Handles [_AuthenticationStatusChanged] events.
@@ -85,55 +85,20 @@ class AuthenticationBloc
85
85
),
86
86
);
87
87
} on InvalidInputException catch (e) {
88
- emit (
89
- state.copyWith (
90
- status: AuthenticationStatus .failure,
91
- exception: e,
92
- ),
93
- );
88
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
94
89
} on UnauthorizedException catch (e) {
95
- emit (
96
- state.copyWith (
97
- status: AuthenticationStatus .failure,
98
- exception: e,
99
- ),
100
- );
90
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
101
91
} on ForbiddenException catch (e) {
102
- emit (
103
- state.copyWith (
104
- status: AuthenticationStatus .failure,
105
- exception: e,
106
- ),
107
- );
92
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
108
93
} on NetworkException catch (e) {
109
- emit (
110
- state.copyWith (
111
- status: AuthenticationStatus .failure,
112
- exception: e,
113
- ),
114
- );
94
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
115
95
} on ServerException catch (e) {
116
- emit (
117
- state.copyWith (
118
- status: AuthenticationStatus .failure,
119
- exception: e,
120
- ),
121
- );
96
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
122
97
} on OperationFailedException catch (e) {
123
- emit (
124
- state.copyWith (
125
- status: AuthenticationStatus .failure,
126
- exception: e,
127
- ),
128
- );
129
- } on HtHttpException catch (e) {
130
- // Catch any other HtHttpException subtypes
131
- emit (
132
- state.copyWith (
133
- status: AuthenticationStatus .failure,
134
- exception: e,
135
- ),
136
- );
98
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
99
+ } on HttpException catch (e) {
100
+ // Catch any other HttpException subtypes
101
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
137
102
} catch (e) {
138
103
// Catch any other unexpected errors
139
104
emit (
@@ -161,55 +126,20 @@ class AuthenticationBloc
161
126
// On success, the _AuthenticationStatusChanged listener will handle
162
127
// emitting AuthenticationAuthenticated.
163
128
} on InvalidInputException catch (e) {
164
- emit (
165
- state.copyWith (
166
- status: AuthenticationStatus .failure,
167
- exception: e,
168
- ),
169
- );
129
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
170
130
} on AuthenticationException catch (e) {
171
- emit (
172
- state.copyWith (
173
- status: AuthenticationStatus .failure,
174
- exception: e,
175
- ),
176
- );
131
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
177
132
} on NotFoundException catch (e) {
178
- emit (
179
- state.copyWith (
180
- status: AuthenticationStatus .failure,
181
- exception: e,
182
- ),
183
- );
133
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
184
134
} on NetworkException catch (e) {
185
- emit (
186
- state.copyWith (
187
- status: AuthenticationStatus .failure,
188
- exception: e,
189
- ),
190
- );
135
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
191
136
} on ServerException catch (e) {
192
- emit (
193
- state.copyWith (
194
- status: AuthenticationStatus .failure,
195
- exception: e,
196
- ),
197
- );
137
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
198
138
} on OperationFailedException catch (e) {
199
- emit (
200
- state.copyWith (
201
- status: AuthenticationStatus .failure,
202
- exception: e,
203
- ),
204
- );
205
- } on HtHttpException catch (e) {
206
- // Catch any other HtHttpException subtypes
207
- emit (
208
- state.copyWith (
209
- status: AuthenticationStatus .failure,
210
- exception: e,
211
- ),
212
- );
139
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
140
+ } on HttpException catch (e) {
141
+ // Catch any other HttpException subtypes
142
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
213
143
} catch (e) {
214
144
// Catch any other unexpected errors
215
145
emit (
@@ -233,34 +163,14 @@ class AuthenticationBloc
233
163
// On success, the _AuthenticationStatusChanged listener will handle
234
164
// emitting AuthenticationUnauthenticated.
235
165
} on NetworkException catch (e) {
236
- emit (
237
- state.copyWith (
238
- status: AuthenticationStatus .failure,
239
- exception: e,
240
- ),
241
- );
166
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
242
167
} on ServerException catch (e) {
243
- emit (
244
- state.copyWith (
245
- status: AuthenticationStatus .failure,
246
- exception: e,
247
- ),
248
- );
168
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
249
169
} on OperationFailedException catch (e) {
250
- emit (
251
- state.copyWith (
252
- status: AuthenticationStatus .failure,
253
- exception: e,
254
- ),
255
- );
256
- } on HtHttpException catch (e) {
257
- // Catch any other HtHttpException subtypes
258
- emit (
259
- state.copyWith (
260
- status: AuthenticationStatus .failure,
261
- exception: e,
262
- ),
263
- );
170
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
171
+ } on HttpException catch (e) {
172
+ // Catch any other HttpException subtypes
173
+ emit (state.copyWith (status: AuthenticationStatus .failure, exception: e));
264
174
} catch (e) {
265
175
emit (
266
176
state.copyWith (
0 commit comments