pinax-network / substreams-sink

Substreams Sink library
MIT License
4 stars 1 forks source link

Api token should be optional #3

Closed fschoell closed 1 year ago

fschoell commented 1 year ago

There are cases where an api token is not necessary (internal use for example), so the sink should not enforce this.

DenisCarriere commented 1 year ago

Should be working, needs a bit more testing, but the @substreams/core library handles adding or not adding authorization based on header requests

https://github.com/substreams-js/substreams-js/blob/main/packages/core/src/auth/createAuthInterceptor.ts#L5C19-L5C19

import type { Interceptor } from "@bufbuild/connect";

export function createAuthInterceptor(token: string): Interceptor {
  return (next) => async (req) => {
    if (!req.header.has("Authorization")) {
      req.header.set("Authorization", `Bearer ${token}`);
    }

    return next(req);
  };
}