First commit

This commit is contained in:
2025-03-17 13:58:47 +01:00
commit fff5617757
159 changed files with 6972 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import 'package:grpc/grpc.dart';
import 'package:sampleapp/services/auth/auth.dart';
class AuthInterceptor extends ClientInterceptor {
final AuthService authService;
AuthInterceptor(this.authService);
@override
ResponseFuture<R> interceptUnary<Q, R>(
ClientMethod<Q, R> method, Q request, CallOptions options, invoker) {
final metadata = <String, String>{};
metadata['authorization'] = 'Bearer ${authService.accessToken}';
options = options.mergedWith(CallOptions(metadata: metadata));
return invoker(method, request, options);
}
}
class GrpcClient {
static Client initializeClient(AuthService authService, String host, int port, Client Function(ClientChannel, List<ClientInterceptor>) clientFactory) {
final interceptor = AuthInterceptor(authService);
final channel = ClientChannel(
host,
port: port,
options: const ChannelOptions(
credentials: ChannelCredentials.secure(),
),
);
return clientFactory(channel, [interceptor]);
}
}