initialize method

Future<void> initialize()

Initializes the user authentication state and refreshes the token.

Implementation

Future<void> initialize() async {
  const key = 'keycloak:hasRunBefore';
  final prefs = SharedPreferencesAsync();
  final hasRunBefore = await prefs.getBool(key) ?? false;

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

  try {
    _isInitialized = true;
    await updateToken();
  } catch (e, s) {
    _isInitialized = false;
    onError('Failed to initialize plugin.', e, s);
  }
}