Skip to content

High performance self-hosted photo and video management solution.

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

avaness5a2fc20b2095
diff --git a/mobile/lib/modules/login/ui/login_form.dart b/mobile/lib/modules/login/ui/login_form.dart
index 5f2aaa222c..6c12742e4c 100644
--- a/mobile/lib/modules/login/ui/login_form.dart
+++ b/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,
),
diff --git a/mobile/lib/utils/url_helper.dart b/mobile/lib/utils/url_helper.dart
index b771a6f705..95fcd80786 100644
--- a/mobile/lib/utils/url_helper.dart
+++ b/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() {