No clear way to provide the admin-token
vipafattal opened this issue · comments
Abed Fattal commented
I want to upload a file to storage as an admin and Nhost SDK currently has no clear way to provide the admin token
Abed Fattal commented
I found a way to use the NhostClient with an admin token by overriding the HTPP Client, it would have been great to see some sort of example in the repo, anyway here is how to construct NhostClient with adminToken:
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart' as clients;
final _nhost = NhostClient(
backendUrl: "URL",
httpClientOverride: HTTPClient()
);
class HTTPClient extends clients.IOClient {
final String adminToken;
HTTPClient({required this.adminToken});
@override
Future<clients.IOStreamedResponse> send(http.BaseRequest request) {
request.headers.addAll({"x-hasura-admin-secret":adminToken});
return super.send(request);
}
}