getJWTToken method

  1. @override
Future<Either<Failure, AuthResponse>> getJWTToken({
  1. required String publicKey,
  2. required String privateKey,
})
override

Implementation

@override
Future<Either<Failure, AuthResponse>> getJWTToken({
  required String publicKey,
  required String privateKey,
}) async {
  try {
    final authorization = base64Encode(utf8.encode('$publicKey:$privateKey'));
    final response = await httpClient.post(
      '/login',
      options: Options(
        headers: {
          'Authorization': 'Basic $authorization',
        },
      ),
      data: jsonEncode({
        'public_key': publicKey,
        'private_key': privateKey,
      }),
    );
    final authResponse = AuthResponse.fromJson(response.data);
    return Right(authResponse);
  } catch (e) {
    return Left(
      Failure(
        message: e.toString(),
      ),
    );
  }
}