diff --git a/lib/helpers/sanity_checks.dart b/lib/helpers/sanity_checks.dart index ac8e0d708..f3378aa9d 100644 --- a/lib/helpers/sanity_checks.dart +++ b/lib/helpers/sanity_checks.dart @@ -16,15 +16,13 @@ import 'package:http/http.dart' as http; Future checkServerPaginationUrls({ required String baseUrl, required String token, - - /// Custom client is only used for tests http.Client? client, }) async { final httpClient = client ?? http.Client(); + try { final baseUri = Uri.parse(baseUrl); final expectedHost = baseUri.host; - final expectedPort = baseUri.port; final expectedScheme = baseUri.scheme; final response = await httpClient.get( @@ -36,10 +34,7 @@ Future checkServerPaginationUrls({ ); if (response.statusCode != 200) { - return const SanityCheckResult( - isValid: false, - message: 'Could not reach server endpoint', - ); + return const SanityCheckResult(isValid: false); } final data = jsonDecode(response.body) as Map; @@ -51,35 +46,13 @@ Future checkServerPaginationUrls({ final nextUri = Uri.parse(nextUrl); - if (nextUri.host != expectedHost) { - return SanityCheckResult( - isValid: false, - message: - 'Server misconfiguration detected!\n\n' - 'You are connecting to: $expectedScheme://$expectedHost${expectedPort != 0 ? ":$expectedPort" : ""}\n' - 'But pagination links point to: ${nextUri.scheme}://${nextUri.host}${nextUri.hasPort ? ":${nextUri.port}" : ""}\n\n' - 'This usually means your reverse proxy is not configured correctly.', - detectedUrl: nextUrl, - ); - } - - if (nextUri.scheme != expectedScheme) { - return SanityCheckResult( - isValid: false, - message: - 'Protocol mismatch detected!\n\n' - 'You are using: $expectedScheme\n' - 'But server returns: ${nextUri.scheme}', - detectedUrl: nextUrl, - ); + if (nextUri.host != expectedHost || nextUri.scheme != expectedScheme) { + return const SanityCheckResult(isValid: false); } return const SanityCheckResult(isValid: true); } catch (e) { - return SanityCheckResult( - isValid: false, - message: 'Error checking server configuration: $e', - ); + return const SanityCheckResult(isValid: false); } } @@ -87,11 +60,7 @@ Future checkServerPaginationUrls({ class SanityCheckResult { const SanityCheckResult({ required this.isValid, - this.message, - this.detectedUrl, }); final bool isValid; - final String? message; - final String? detectedUrl; } diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index a1f4cc782..3e0f17e73 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -1241,14 +1241,18 @@ }, "serverConfigIssueTitle": "Server Configuration Issue", "@serverConfigIssueTitle": { - "description": "Title of the dialog shown when server misconfiguration is detected" - }, - "serverConfigIssueWarning": "The app may still work in some cases, but pagination and some features might be broken.", - "@serverConfigIssueWarning": { - "description": "Warning message explaining that the app might not work properly due to server misconfiguration" - }, - "understand": "I understand", - "@understand": { - "description": "Button label to acknowledge and dismiss the server configuration warning" - } + "description": "Title of the dialog shown when server misconfiguration is detected" + }, + "serverConfigIssueMessage": "Server misconfiguration detected, headers are not being passed correctly, please consult the documentation.", + "@serverConfigIssueMessage": { + "description": "Message explaining server misconfiguration and linking to documentation" + }, + "understand": "I understand", + "@understand": { + "description": "Button label to acknowledge and dismiss the server configuration warning" + }, + "viewDocumentation": "View documentation", + "@viewDocumentation": { + "description": "Button label to open the documentation about server configuration" + } } diff --git a/lib/providers/auth.dart b/lib/providers/auth.dart index e2a1e2eef..4cb7a810f 100644 --- a/lib/providers/auth.dart +++ b/lib/providers/auth.dart @@ -55,8 +55,8 @@ class AuthProvider with ChangeNotifier { PackageInfo? applicationVersion; Map metadata = {}; AuthState state = AuthState.loggedOut; - String? _serverConfigWarning; - String? get serverConfigWarning => _serverConfigWarning; + bool _serverConfigWarning = false; + bool get serverConfigWarning => _serverConfigWarning; static const MIN_APP_VERSION_URL = 'min-app-version'; static const SERVER_VERSION_URL = 'version'; @@ -72,7 +72,7 @@ class AuthProvider with ChangeNotifier { /// Clear the server config warnings void clearServerConfigWarning() { - _serverConfigWarning = null; + _serverConfigWarning = false; notifyListeners(); } @@ -255,8 +255,9 @@ class AuthProvider with ChangeNotifier { baseUrl: serverUrl, token: token!, ); - if (!sanityCheck.isValid && sanityCheck.message != null) { - _serverConfigWarning = sanityCheck.message; + + if (!sanityCheck.isValid) { + _serverConfigWarning = true; notifyListeners(); } } catch (e) { diff --git a/lib/screens/auth_screen.dart b/lib/screens/auth_screen.dart index df10acc43..9b46bd67b 100644 --- a/lib/screens/auth_screen.dart +++ b/lib/screens/auth_screen.dart @@ -219,9 +219,9 @@ class _AuthCardState extends State { if (context.mounted && res == LoginActions.proceed) { final authProvider = context.read(); - if (authProvider.serverConfigWarning != null) { + if (authProvider.serverConfigWarning) { if (context.mounted) { - showServerConfigWarning(context, authProvider.serverConfigWarning!); + showServerConfigWarning(context); authProvider.clearServerConfigWarning(); } } diff --git a/lib/widgets/core/server_config_warning_dialog.dart b/lib/widgets/core/server_config_warning_dialog.dart index 429c99e48..acf1e5feb 100644 --- a/lib/widgets/core/server_config_warning_dialog.dart +++ b/lib/widgets/core/server_config_warning_dialog.dart @@ -13,7 +13,7 @@ import 'package:wger/helpers/misc.dart'; import 'package:wger/l10n/generated/app_localizations.dart'; /// Shows a warning dialog when server misconfiguration is detected -void showServerConfigWarning(BuildContext context, String message) { +void showServerConfigWarning(BuildContext context) { final i18n = AppLocalizations.of(context); showDialog( @@ -26,28 +26,22 @@ void showServerConfigWarning(BuildContext context, String message) { Expanded(child: Text(i18n.serverConfigIssueTitle)), ], ), - content: SingleChildScrollView( - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(message), - const SizedBox(height: 16), - Text( - i18n.serverConfigIssueWarning, - style: const TextStyle( - fontStyle: FontStyle.italic, - fontSize: 14, - ), - ), - ], - ), - ), + content: Text(i18n.serverConfigIssueMessage), actions: [ TextButton( onPressed: () => Navigator.pop(context), child: Text(i18n.understand), ), + TextButton( + onPressed: () { + launchURL( + 'https://wger.readthedocs.io/en/latest/administration/errors.html#wrong-pagination-links', + context, + ); + Navigator.pop(context); + }, + child: Text(i18n.viewDocumentation), + ), ], ), ); diff --git a/test/helpers/sanity_checks_test.dart b/test/helpers/sanity_checks_test.dart index ba10aacd0..b61083c98 100644 --- a/test/helpers/sanity_checks_test.dart +++ b/test/helpers/sanity_checks_test.dart @@ -47,8 +47,6 @@ void main() { ); expect(result.isValid, isTrue); - expect(result.message, isNull); - expect(result.detectedUrl, isNull); }); test('detects host mismatch (localhost issue)', () async { @@ -71,10 +69,6 @@ void main() { ); expect(result.isValid, isFalse); - expect(result.message, contains('Server misconfiguration detected')); - expect(result.message, contains('wger.example.com')); - expect(result.message, contains('localhost')); - expect(result.detectedUrl, 'http://localhost:8000/api/v2/exercise/?limit=1&offset=1'); }); test('detects protocol mismatch (https vs http)', () async { @@ -97,9 +91,6 @@ void main() { ); expect(result.isValid, isFalse); - expect(result.message, contains('Protocol mismatch detected')); - expect(result.message, contains('https')); - expect(result.message, contains('http')); }); test('returns valid when next URL is null (no pagination)', () async { @@ -136,7 +127,6 @@ void main() { ); expect(result.isValid, isFalse); - expect(result.message, contains('Could not reach server endpoint')); }); test('handles network errors gracefully', () async { @@ -151,7 +141,6 @@ void main() { ); expect(result.isValid, isFalse); - expect(result.message, contains('Error checking server configuration')); }); test('includes correct headers in request', () async { @@ -200,26 +189,4 @@ void main() { expect(result.isValid, isTrue); }); }); - - group('SanityCheckResult', () { - test('creates valid result correctly', () { - const result = SanityCheckResult(isValid: true); - - expect(result.isValid, isTrue); - expect(result.message, isNull); - expect(result.detectedUrl, isNull); - }); - - test('creates invalid result with message', () { - const result = SanityCheckResult( - isValid: false, - message: 'Test error', - detectedUrl: 'http://localhost', - ); - - expect(result.isValid, isFalse); - expect(result.message, 'Test error'); - expect(result.detectedUrl, 'http://localhost'); - }); - }); }