Преглед изворни кода

fix(mobile): server endpoint input auto parse https when not specified (#5326)

This fixes issue #4397 and automatically adds the https protocol to the server endpoint url if it is missing

Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
avaness пре 1 година
родитељ
комит
5a2fc20b20
2 измењених фајлова са 7 додато и 7 уклоњено
  1. 5 5
      mobile/lib/modules/login/ui/login_form.dart
  2. 2 2
      mobile/lib/utils/url_helper.dart

+ 5 - 5
mobile/lib/modules/login/ui/login_form.dart

@@ -48,7 +48,7 @@ class LoginForm extends HookConsumerWidget {
     /// Fetch the server login credential and enables oAuth login if necessary
     /// Returns true if successful, false otherwise
     Future<bool> getServerLoginCredential() async {
-      final serverUrl = serverEndpointController.text.trim();
+      final serverUrl = sanitizeUrl(serverEndpointController.text);
 
       // Guard empty URL
       if (serverUrl.isEmpty) {
@@ -150,7 +150,7 @@ class LoginForm extends HookConsumerWidget {
             await ref.read(authenticationProvider.notifier).login(
                   usernameController.text,
                   passwordController.text,
-                  serverEndpointController.text.trim(),
+                  sanitizeUrl(serverEndpointController.text),
                 );
         if (isAuthenticated) {
           // Resume backup (if enable) then navigate
@@ -187,7 +187,7 @@ class LoginForm extends HookConsumerWidget {
 
       try {
         oAuthServerConfig = await oAuthService
-            .getOAuthServerConfig(serverEndpointController.text);
+            .getOAuthServerConfig(sanitizeUrl(serverEndpointController.text));
 
         isLoading.value = true;
       } catch (e) {
@@ -209,7 +209,7 @@ class LoginForm extends HookConsumerWidget {
               .watch(authenticationProvider.notifier)
               .setSuccessLoginInfo(
                 accessToken: loginResponseDto.accessToken,
-                serverUrl: serverEndpointController.text,
+                serverUrl: sanitizeUrl(serverEndpointController.text),
               );
 
           if (isSuccess) {
@@ -305,7 +305,7 @@ class LoginForm extends HookConsumerWidget {
           crossAxisAlignment: CrossAxisAlignment.stretch,
           children: [
             Text(
-              serverEndpointController.text,
+              sanitizeUrl(serverEndpointController.text),
               style: context.textTheme.displaySmall,
               textAlign: TextAlign.center,
             ),

+ 2 - 2
mobile/lib/utils/url_helper.dart

@@ -3,10 +3,10 @@ import 'package:immich_mobile/shared/models/store.dart';
 String sanitizeUrl(String url) {
   // Add schema if none is set
   final urlWithSchema =
-      url.startsWith(RegExp(r"https?://")) ? url : "https://$url";
+      url.trimLeft().startsWith(RegExp(r"https?://")) ? url : "https://$url";
 
   // Remove trailing slash(es)
-  return urlWithSchema.replaceFirst(RegExp(r"/+$"), "");
+  return urlWithSchema.trimRight().replaceFirst(RegExp(r"/+$"), "");
 }
 
 String? getServerUrl() {