Effect CommunityEC
Effect Community2y ago
11 replies
Riordan

Implementing Authorization in RPC Requests with Effect RPC and CommandMetadata Layer

Using Effect RPC - what would be the best way to take an Authorization header, flatMap it, and throw the result into a layer that I can consume anywhere inside the rpc request handler?
Example layer below.
export class CommandMetadata extends Context.Tag("CommandMetadata")<
  CommandMetadata,
  { readonly userId: string | null }
>() {}
export const { userId: GetUserId } = Effect.serviceConstants(CommandMetadata);
export const makeCommandMetadataLayer = (userId: string | null) =>
  Layer.succeed(CommandMetadata, CommandMetadata.of({ userId }));
Was this page helpful?