Skip to content

Commit

Permalink
👔 Clear secure storage after reinstalls
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Fakhri authored and fa-fifi committed Sep 4, 2024
1 parent 2ecd64e commit 8406d51
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
72 changes: 72 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.2"
file:
dependency: transitive
description:
name: file
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -218,6 +226,62 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.8"
shared_preferences:
dependency: transitive
description:
name: shared_preferences
sha256: "746e5369a43170c25816cc472ee016d3a66bc13fcf430c0bc41ad7b4b2922051"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
sha256: "480ba4345773f56acda9abf5f50bd966f581dac5d514e5fc4a18c62976bbba7e"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
shared_preferences_foundation:
dependency: transitive
description:
name: shared_preferences_foundation
sha256: c4b35f6cb8f63c147312c054ce7c2254c8066745125264f0c88739c417fc9d9f
url: "https://pub.dev"
source: hosted
version: "2.5.2"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
sha256: "580abfd40f415611503cae30adf626e6656dfb2f0cee8f465ece7b6defb40f2f"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
sha256: "57cbf196c486bc2cf1f02b85784932c6094376284b3ad5779d1b1c6c6a816b80"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
sha256: d2ca4132d3946fec2184261726b355836a82c33d7d5b67af32692aff18a4684e
url: "https://pub.dev"
source: hosted
version: "2.4.2"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
sha256: "94ef0f72b2d71bc3e700e025db3710911bd51a71cefb65cc609dd0d9a982e3c1"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -231,6 +295,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062
url: "https://pub.dev"
source: hosted
version: "1.0.0"
win32:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions lib/keycloak_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:io';

import 'package:flutter_appauth/flutter_appauth.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:shared_preferences/shared_preferences.dart';

part 'src/config.dart';
part 'src/constants.dart';
Expand Down
12 changes: 10 additions & 2 deletions lib/src/wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,18 @@ class KeycloakWrapper {
}

/// Initializes the user authentication state and refreshes the token.
void initialize() {
Future<void> initialize() async {
final prefs = SharedPreferencesAsync();
final hasRunBefore = await prefs.getBool('hasRunBefore') ?? false;

if (!hasRunBefore) {
_secureStorage.deleteAll();
prefs.setBool('hasRunBefore', true);
}

try {
_isInitialized = true;
updateToken();
await updateToken();
} catch (e, s) {
_isInitialized = false;
onError('Failed to initialize plugin.', e, s);
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies:
sdk: flutter
flutter_appauth: ^6.0.6
flutter_secure_storage: ^9.2.2
shared_preferences: ^2.3.2

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 8406d51

Please sign in to comment.