GenkitG
Genkit16mo ago
18 replies
sad-indigo

Authorization and integrity  |  Genkit  ...

I am looking at the Authentification, seems like the showed examples result in type errors: https://firebase.google.com/docs/genkit/auth#non-firebase_http_authorization

Due to
req.auth
not being a valid field on the req object.

Something like this works, but doesn't look prettiest. Any option how we can better define the auth schema across the framework?

    middleware: [
      (req, res, next) => {
        (
          req as typeof req & {
            auth: {
              apiKey?: string;
            };
          }
        ).auth = {
          apiKey: req.headers["x-api-key"] as string,
        };
        next();
      },
    ],
    authPolicy: (auth) => {
      // auth is still any in this case
      if (!auth?.apiKey) {
        throw new Error("Authorization required.");
      }

      // ... verify API key
    },


When using the Firebase onFlow, the policy is better defined with strong types even in the example (image2)
image.png
image2.png
Was this page helpful?