mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
chore(mobile): refactor authentication (#14322)
This commit is contained in:
parent
5417e34fb6
commit
21f14be949
26 changed files with 619 additions and 354 deletions
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:immich_mobile/entities/store.entity.dart';
|
||||
import 'package:immich_mobile/utils/url_helper.dart';
|
||||
|
|
@ -69,7 +70,7 @@ class ApiService implements Authentication {
|
|||
final endpoint = await _resolveEndpoint(serverUrl);
|
||||
setEndpoint(endpoint);
|
||||
|
||||
// Save in hivebox for next startup
|
||||
// Save in local database for next startup
|
||||
Store.put(StoreKey.serverEndpoint, endpoint);
|
||||
return endpoint;
|
||||
}
|
||||
|
|
@ -148,11 +149,27 @@ class ApiService implements Authentication {
|
|||
return "";
|
||||
}
|
||||
|
||||
setAccessToken(String accessToken) {
|
||||
void setAccessToken(String accessToken) {
|
||||
_accessToken = accessToken;
|
||||
Store.put(StoreKey.accessToken, accessToken);
|
||||
}
|
||||
|
||||
Future<void> setDeviceInfoHeader() async {
|
||||
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
|
||||
|
||||
if (Platform.isIOS) {
|
||||
final iosInfo = await deviceInfoPlugin.iosInfo;
|
||||
authenticationApi.apiClient
|
||||
.addDefaultHeader('deviceModel', iosInfo.utsname.machine);
|
||||
authenticationApi.apiClient.addDefaultHeader('deviceType', 'iOS');
|
||||
} else {
|
||||
final androidInfo = await deviceInfoPlugin.androidInfo;
|
||||
authenticationApi.apiClient
|
||||
.addDefaultHeader('deviceModel', androidInfo.model);
|
||||
authenticationApi.apiClient.addDefaultHeader('deviceType', 'Android');
|
||||
}
|
||||
}
|
||||
|
||||
static Map<String, String> getRequestHeaders() {
|
||||
var accessToken = Store.get(StoreKey.accessToken, "");
|
||||
var customHeadersStr = Store.get(StoreKey.customHeaders, "");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue