initialize method

Future<void> initialize()

Initializes the service, setting up the Dio instance and loading credentials.

Implementation

Future<void> initialize() async {
  // Configure Dio with authorization header
  _dio = Dio(
    BaseOptions(
      headers: {
        'Authorization': 'Bearer $accessToken',
      },
    ),
  )..interceptors.add(
      InterceptorsWrapper(
        onRequest: (options, handler) async {
          // Refresh access token if needed before each request
          await _refreshAccessTokenIfNeeded();
          options.headers['Authorization'] = 'Bearer $accessToken';
          return handler.next(options);
        },
      ),
    );

  // Load OAuth credentials from secure storage
  await _loadCredentialsFromStorage();
}