storeTokens method

Future<void> storeTokens({
  1. required String accessToken,
  2. required String refreshToken,
  3. int? customerId,
})

Store tokens in secure storage

Implementation

Future<void> storeTokens({
  required String accessToken,
  required String refreshToken,
  int? customerId,
}) async {
  try {
    await _secureStorage.write(
      key: _storageKeyAccessToken,
      value: accessToken,
    );
    await _secureStorage.write(
      key: _storageKeyRefreshToken,
      value: refreshToken,
    );
    if (customerId != null) {
      await _secureStorage.write(
        key: _storageKeyCustomerId,
        value: customerId.toString(),
      );
    }

    _accessToken = accessToken;
    _refreshToken = refreshToken;
    _customerId = customerId;
  } catch (e) {
    print('Failed to store tokens: $e');
  }
}