Initial web socket client support
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:frontend/providers/auth.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
@@ -15,11 +16,30 @@ Dio dio(Ref ref) {
|
||||
receiveTimeout: const Duration(seconds: 3),
|
||||
));
|
||||
|
||||
dio.interceptors.add(LogInterceptor(responseBody: true));
|
||||
final jwt = ref.watch(jwtNotifierProvider).valueOrNull;
|
||||
|
||||
dio.interceptors.addAll([JwtInterceptor(jwt: jwt), CustomLogInterceptor()]);
|
||||
|
||||
logger.fine('Created new Dio object');
|
||||
|
||||
return dio;
|
||||
}
|
||||
|
||||
// Adds the jwt to
|
||||
class JwtInterceptor extends Interceptor {
|
||||
final String? jwt;
|
||||
|
||||
JwtInterceptor({required this.jwt});
|
||||
|
||||
@override
|
||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||
if (jwt != null) {
|
||||
options.headers['Authorization'] = 'Bearer $jwt';
|
||||
}
|
||||
handler.next(options);
|
||||
}
|
||||
}
|
||||
|
||||
// Create a custom LogInterceptor using the logger object
|
||||
class CustomLogInterceptor extends Interceptor {
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user