dio_refresh_bot 2.2.1 copy "dio_refresh_bot: ^2.2.1" to clipboard
dio_refresh_bot: ^2.2.1 copied to clipboard

Dio interceptor which makes refresh token mechanism simple, flexible and reactive.

example/example.dart

import 'package:dio/dio.dart';
import 'package:dio_refresh_bot/dio_refresh_bot.dart';

// ignore_for_file: avoid_print
void main() {
  final dio = Dio();

  final storage = BotMemoryTokenStorage<AuthToken>();

  dio.interceptors.add(
    RefreshTokenInterceptor<AuthToken>(
      tokenStorage: storage,
      refreshToken: (token, tokenDio) async {
        final response = await tokenDio.post<dynamic>(
          'https://example/refresh',
          data: {'refreshToken': token.refreshToken},
        );

        return AuthToken.fromMap(response.data as Map<String, dynamic>);
      },
    ),
  );
  // listen to the token changes
  storage.stream.listen(print);

  // listen to auth state changes
  // storage.authenticationStatus.listen(print);
}
30
likes
150
points
329
downloads

Publisher

verified publisherflutterbots.dev

Weekly Downloads

Dio interceptor which makes refresh token mechanism simple, flexible and reactive.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

bot_storage, dio, equatable, meta, rxdart

More

Packages that depend on dio_refresh_bot