Skip to content

Commit

Permalink
fix: bug with secure storage juliansteenbakker/flutter_secure_storage…
Browse files Browse the repository at this point in the history
  • Loading branch information
sergdeus committed Sep 13, 2022
1 parent 72f18bb commit 9132ad0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/build_from_tags_ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# https://stefma.medium.com/how-to-store-a-android-keystore-safely-on-github-actions-f0cef9413784
# Creates release when tag pushed
# Create tag:
# git tag <tagname>
# Push it:
# git push origin <tag_name>
# After that release will be created.

# Used Github secrets
# KEY_PROPERTIES - file
# RELEASE_AGORADESK_KEYSTORE
# RELEASE_AGORADESK_KEYSTORE_SECRET
Expand All @@ -14,8 +21,8 @@ name: BuildFromTagsCI

on:
push:
# tags:
# - "v*.*.*"
tags:
- "v*.*.*"
jobs:
build:
name: Build APK & AppBundle
Expand Down
4 changes: 3 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.agoradesk.app">
package="com.agoradesk.app"
android:allowBackup="false"
android:fullBackupContent="@xml/backup_rules">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
Expand Down
4 changes: 4 additions & 0 deletions android/app/src/main/res/xml/backup_rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<exclude domain="sharedpref" path="FlutterSecureStorage"/>
</full-backup-content>
16 changes: 14 additions & 2 deletions lib/core/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,24 @@ class _AppState extends State<App> with WidgetsBindingObserver, StringMixin, Cou
}

/// Configure [ApiClient] with cache
final String? token = await _secureStorage.read(SecureStorageKey.token);
String? token;
try {
token = await _secureStorage.read(SecureStorageKey.token);
} catch (e) {
_secureStorage.deleteAll();
}

debugPrint('[init app, API token from secured storage] $token');
_api.accessToken = token;

/// Set pin code state
final String? pin = await _secureStorage.read(SecureStorageKey.pin);
String? pin;
try {
pin = await _secureStorage.read(SecureStorageKey.pin);
} catch (e) {
_secureStorage.deleteAll();
}

appState.hasPinCode = token != null && pin != null;
appState.pinCode = pin;
await _afterConfigInit();
Expand Down
7 changes: 6 additions & 1 deletion lib/features/main/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ class _MainScreenState extends State<MainScreen> {
} else {
await SecureStorage.ensureInitialized();
final SecureStorage _secureStorage = SecureStorage();
final l = await _secureStorage.read(SecureStorageKey.locale);
String? l;
try {
l = await _secureStorage.read(SecureStorageKey.locale);
} catch (e) {
_secureStorage.deleteAll();
}
final langCode = l ?? Platform.localeName.substring(0, 2);
await FlutterForegroundTask.startService(
notificationTitle:
Expand Down
9 changes: 8 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,14 @@ Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
try {
await SecureStorage.ensureInitialized();
final SecureStorage _secureStorage = SecureStorage();
final l = await _secureStorage.read(SecureStorageKey.locale);

String? l;
try {
l = await _secureStorage.read(SecureStorageKey.locale);
} catch (e) {
_secureStorage.deleteAll();
}

final String langCode = l ?? Platform.localeName.substring(0, 2);
final PushModel push = PushModel.fromJson(message.data);
final Map<String, String> payload = push.toJson().map((key, value) => MapEntry(key, value?.toString() ?? ''));
Expand Down

0 comments on commit 9132ad0

Please sign in to comment.