From 2d7fa205579559465abd5b888cb8d089e2df26bf Mon Sep 17 00:00:00 2001 From: Ashley Bailey Date: Wed, 8 Jan 2025 22:29:42 +0000 Subject: [PATCH] Automatically apply /api to server URL if missing --- mobile/lib/widgets/forms/login/login_form.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mobile/lib/widgets/forms/login/login_form.dart b/mobile/lib/widgets/forms/login/login_form.dart index c6b2a4c489..df447d80cf 100644 --- a/mobile/lib/widgets/forms/login/login_form.dart +++ b/mobile/lib/widgets/forms/login/login_form.dart @@ -94,12 +94,14 @@ class LoginForm extends HookConsumerWidget { ); } - // Automatically add /api to URL if missing - if (!serverUrl.endsWith('/api') || serverUrl.endsWith('/api/')) { - if (!serverUrl.endsWith('/')) { - serverUrl = String($sanitizedUrl + '/api'); - } - serverUrl = String($sanitizedUrl + 'api'); + // Automatically add /api to serverUrl if missing + serverUrl = serverUrl.trim(); + + // Check if the string ends with '/api/' and remove the trailing slash if it does or add '/api' if the string doesn't end with '/api' + if (serverUrl.endsWith('/api/')) { + serverUrl = serverUrl.substring(0, serverUrl.length - 1); + } else if (!serverUrl.endsWith('/api')) { + serverUrl = '$serverUrl/api'; }