Skip to content

Refatrcor auth hints for demo envirement #24

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

Merged
merged 7 commits into from
Jul 5, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions lib/app/bloc/app_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ class AppBloc extends Bloc<AppEvent, AppState> {
}) : _authenticationRepository = authenticationRepository,
_userAppSettingsRepository = userAppSettingsRepository,
_appConfigRepository = appConfigRepository,
_environment = environment,
super(
const AppState(),
AppState(environment: environment),
) {
on<AppUserChanged>(_onAppUserChanged);
on<AppLogoutRequested>(_onLogoutRequested);
Expand All @@ -37,7 +36,6 @@ class AppBloc extends Bloc<AppEvent, AppState> {
final HtAuthRepository _authenticationRepository;
final HtDataRepository<UserAppSettings> _userAppSettingsRepository;
final HtDataRepository<AppConfig> _appConfigRepository;
final local_config.AppEnvironment _environment;
late final StreamSubscription<User?> _userSubscription;

/// Handles user changes and loads initial settings once user is available.
Expand Down
2 changes: 1 addition & 1 deletion lib/authentication/view/email_code_verification_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class EmailCodeVerificationPage extends StatelessWidget {
children: [
const SizedBox(height: AppSpacing.md),
Text(
l10n.demoVerificationCodeMessage('123456'),
l10n.demoCodeHint('123456'),
style: textTheme.bodyMedium?.copyWith(
color: colorScheme.secondary,
fontWeight: FontWeight.bold,
Comment on lines 84 to 88

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This refactoring appears to be incomplete. The hint for the demo verification code should only be displayed in the demo environment.

There are two issues here:

  1. Incorrect condition: This hint is likely displayed based on a condition like kDebugMode (which is outside the diff but can be inferred from similar code), but it should be conditional on state.environment == AppEnvironment.demo. Please use a BlocSelector to check the environment, similar to the implementation in request_code_page.dart. This will fix the bug where the hint is shown in non-demo debug builds and hidden in release demo builds.
  2. Hardcoded value: The verification code '123456' is hardcoded. For better maintainability, consider moving this value into AppConfig.

Expand Down
22 changes: 22 additions & 0 deletions lib/authentication/view/request_code_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ht_dashboard/app/bloc/app_bloc.dart';
import 'package:ht_dashboard/app/config/config.dart';
import 'package:go_router/go_router.dart';
import 'package:ht_dashboard/authentication/bloc/authentication_bloc.dart';
import 'package:ht_dashboard/l10n/l10n.dart';
Expand Down Expand Up @@ -129,6 +131,26 @@ class _RequestCodeView extends StatelessWidget {
),
textAlign: TextAlign.center,
),
// Display demo email if in demo environment
BlocSelector<AppBloc, AppState, AppEnvironment?>(
selector: (state) => state.environment,
builder: (context, environment) {
if (environment == AppEnvironment.demo) {
return Padding(
padding: const EdgeInsets.only(top: AppSpacing.lg),
child: Text(
l10n.demoEmailHint('[email protected]'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The demo email '[email protected]' is hardcoded. To improve maintainability and centralize configuration, please consider moving this value to AppConfig. This makes it easier to manage demo credentials without changing the UI code.

style: textTheme.bodyMedium?.copyWith(
color: colorScheme.secondary,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
);
}
return const SizedBox.shrink();
},
),
const SizedBox(height: AppSpacing.xxl),
_EmailLinkForm(isLoading: isLoading),
],
Expand Down
12 changes: 12 additions & 0 deletions lib/l10n/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,18 @@ abstract class AppLocalizations {
/// In en, this message translates to:
/// **'Disabled'**
String get appStatusDisabled;

/// Hint text shown in demo environment for the login email.
///
/// In en, this message translates to:
/// **'For demo, use email: {email}'**
String demoEmailHint(String email);

/// Hint text shown in demo environment for the verification code.
///
/// In en, this message translates to:
/// **'For demo, use code: {code}'**
String demoCodeHint(String code);
}

class _AppLocalizationsDelegate
Expand Down
10 changes: 10 additions & 0 deletions lib/l10n/app_localizations_ar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -737,4 +737,14 @@ class AppLocalizationsAr extends AppLocalizations {

@override
String get appStatusDisabled => 'معطل';

@override
String demoEmailHint(String email) {
return 'للعرض التجريبي، استخدم البريد الإلكتروني: $email';
}

@override
String demoCodeHint(String code) {
return 'للعرض التجريبي، استخدم الرمز: $code';
}
}
10 changes: 10 additions & 0 deletions lib/l10n/app_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -735,4 +735,14 @@ class AppLocalizationsEn extends AppLocalizations {

@override
String get appStatusDisabled => 'Disabled';

@override
String demoEmailHint(String email) {
return 'For demo, use email: $email';
}

@override
String demoCodeHint(String code) {
return 'For demo, use code: $code';
}
}
20 changes: 20 additions & 0 deletions lib/l10n/arb/app_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -893,5 +893,25 @@
"appStatusDisabled": "معطل",
"@appStatusDisabled": {
"description": "نص حالة التطبيق 'معطل'"
},
"demoEmailHint": "للعرض التجريبي، استخدم البريد الإلكتروني: {email}",
"@demoEmailHint": {
"description": "Hint text shown in demo environment for the login email.",
"placeholders": {
"email": {
"type": "String",
"example": "[email protected]"
}
}
},
"demoCodeHint": "للعرض التجريبي، استخدم الرمز: {code}",
"@demoCodeHint": {
"description": "Hint text shown in demo environment for the verification code.",
"placeholders": {
"code": {
"type": "String",
"example": "123456"
}
}
}
}
21 changes: 21 additions & 0 deletions lib/l10n/arb/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -893,5 +893,26 @@
"appStatusDisabled": "Disabled",
"@appStatusDisabled": {
"description": "Text for the 'Disabled' app status"
},
"demoEmailHint": "For demo, use email: {email}",
"@demoEmailHint": {
"description": "Hint text shown in demo environment for the login email.",
"placeholders": {
"email": {
"type": "String",
"example": "[email protected]"
}
}
},
"demoCodeHint": "For demo, use code: {code}",
"@demoCodeHint": {
"description": "Hint text shown in demo environment for the verification code.",
"placeholders": {
"code": {
"type": "String",
"example": "123456"
}
}
}

}
Loading