Skip to content

Commit 7a10ca4

Browse files
authored
Merge pull request #34 from headlines-toolkit/fix_misc_auth_bugs
Fix misc auth bugs
2 parents 9eeae0b + d54960b commit 7a10ca4

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lib/authentication/bloc/authentication_bloc.dart

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AuthenticationBloc
2626
: _authenticationRepository = authenticationRepository,
2727
super(AuthenticationInitial()) {
2828
// Listen to authentication state changes from the repository
29-
_authenticationRepository.authStateChanges.listen(
29+
_userAuthSubscription = _authenticationRepository.authStateChanges.listen(
3030
(user) => add(_AuthenticationUserChanged(user: user)),
3131
);
3232

@@ -42,6 +42,7 @@ class AuthenticationBloc
4242
}
4343

4444
final HtAuthRepository _authenticationRepository;
45+
late final StreamSubscription<User?> _userAuthSubscription;
4546

4647
/// Handles [_AuthenticationUserChanged] events.
4748
Future<void> _onAuthenticationUserChanged(
@@ -83,7 +84,8 @@ class AuthenticationBloc
8384
emit(AuthenticationFailure('Operation failed: ${e.message}'));
8485
} on HtHttpException catch (e) {
8586
// Catch any other HtHttpException subtypes
86-
emit(AuthenticationFailure('HTTP error: ${e.message}'));
87+
final message = e.message.isNotEmpty ? e.message : 'An unspecified HTTP error occurred.';
88+
emit(AuthenticationFailure('HTTP error: $message'));
8789
} catch (e) {
8890
// Catch any other unexpected errors
8991
emit(AuthenticationFailure('An unexpected error occurred: $e'));
@@ -102,9 +104,9 @@ class AuthenticationBloc
102104
// On success, the _AuthenticationUserChanged listener will handle
103105
// emitting AuthenticationAuthenticated.
104106
} on InvalidInputException catch (e) {
105-
emit(AuthenticationFailure('Invalid input: ${e.message}'));
107+
emit(AuthenticationFailure(e.message)); // Use specific error message
106108
} on AuthenticationException catch (e) {
107-
emit(AuthenticationFailure('Authentication failed: ${e.message}'));
109+
emit(AuthenticationFailure(e.message)); // Use specific error message
108110
} on NetworkException catch (_) {
109111
emit(const AuthenticationFailure('Network error occurred.'));
110112
} on ServerException catch (e) {
@@ -155,6 +157,10 @@ class AuthenticationBloc
155157
await _authenticationRepository.signOut();
156158
// On success, the _AuthenticationUserChanged listener will handle
157159
// emitting AuthenticationUnauthenticated.
160+
// No need to emit AuthenticationLoading() before calling signOut if
161+
// the authStateChanges listener handles the subsequent state update.
162+
// However, if immediate feedback is desired, it can be kept.
163+
// For now, let's assume the listener is sufficient.
158164
} on NetworkException catch (_) {
159165
emit(const AuthenticationFailure('Network error occurred.'));
160166
} on ServerException catch (e) {
@@ -168,4 +174,10 @@ class AuthenticationBloc
168174
emit(AuthenticationFailure('An unexpected error occurred: $e'));
169175
}
170176
}
177+
178+
@override
179+
Future<void> close() {
180+
_userAuthSubscription.cancel();
181+
return super.close();
182+
}
171183
}

lib/authentication/view/email_code_verification_page.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ class _EmailCodeVerificationFormState
166166
const SizedBox(height: AppSpacing.xxl), // Increased spacing
167167
ElevatedButton(
168168
style: ElevatedButton.styleFrom(
169-
padding: const EdgeInsets.symmetric(vertical: AppSpacing.md),
169+
padding: const EdgeInsets.symmetric(
170+
vertical: AppSpacing.md,
171+
horizontal: AppSpacing.lg, // Added horizontal padding
172+
),
170173
textStyle: textTheme.labelLarge,
171174
),
172175
onPressed: widget.isLoading ? null : _submitForm,

0 commit comments

Comments
 (0)