Handling Context in Middleware for JWT Authorization in TypeScript

How do I properly provide the context for a middleware? I wrote an auth middleware that will extract a JWT, parse it, and append it to... something, I'll be honest I dont' really know what, I copied it from the HttpMiddleware internals. When I try to access this context though via
  const token = yield* AuthorizationToken;
  yield* Effect.log(token);


My effect entry-point complains that the type of the decoded token is not assignable to never, indicating an unfulfilled dependency

the service in question
export type AuthorizationToken = typeof AuthorizationSchema.Type;
export const AuthorizationToken =
  Context.GenericTag<AuthorizationToken>("AuthorizationToken");

export const authorizationMiddleware: <E, R>(
  httpApp: HttpApp.Default<E, R>,
) => HttpApp.Default<E, R> = (httpApp) =>
  Effect.withFiberRuntime((fiber) =>
    Effect.gen(function* () {
      const context = fiber.getFiberRef(FiberRef.currentContext);
      const request = Context.unsafeGet(
        context,
        HttpServerRequest.HttpServerRequest,
      );
      const authorization =
        request.headers.authorization ?? request.headers.Authorization;
      const decoded =
        yield* Schema.decodeUnknown(AuthorizationSchema)(authorization);

      return yield* Effect.locally(
        httpApp,
        FiberRef.currentContext,
        Context.add(context, AuthorizationToken, decoded),
      );
    }).pipe(
      Effect.catchAll((e) =>
        HttpServerResponse.unsafeJson(
          {
            message: "Unauthorized",
          },
          { status: 401 },
        ),
      ),
    ),
  );
Was this page helpful?