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>
This commit is contained in:
avaness 2023-11-28 22:02:19 -06:00 committed by GitHub
parent 2a45ad147c
commit 5a2fc20b20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View file

@ -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,
),

View file

@ -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() {