Files
zitadel/packages/zitadel-client/src/interceptors.ts
2024-07-26 00:30:45 -04:00

17 lines
536 B
TypeScript

import type { Interceptor } from "@connectrpc/connect";
/**
* Creates an interceptor that adds an Authorization header with a Bearer token.
* @param token
*/
export function NewAuthorizationBearerInterceptor(token: string): Interceptor {
return (next) => (req) => {
// TODO: I am not what is the intent of checking for the Authorization header
// and setting it if it is not present.
if (!req.header.get("Authorization")) {
req.header.set("Authorization", `Bearer ${token}`);
}
return next(req);
};
}