WaspW
Wasp12mo ago
genyus

Custom endpoint missing context user

I've created a custom API endpoint that needs to be authenticated. As per the documentation, I set the
auth
field to true, but when a request is received, there's no Authorization header and the context.user object is
null
even though the user is logged in. I'm not sure what I'm missing? Do I need to set the header manually?

For context, I have an API namespace applied to prevent the CORS errors I was experiencing initially.

api getDocumentMarkupApi {
  fn: import { getDocumentMarkup } from "@src/server/api/documents.js",
  entities: [Document],
  httpRoute: (GET, "/api/documents/:id/render"),
  auth: true
}

apiNamespace customApi {
  middlewareConfigFn: import { apiMiddleware } from "@src/server/utils",
  path: "/api"
}
In Wasp, the default client-server interaction mechanism is through Operations. However, if you need a specific URL method/path, or a specific response, Operations may not be suitable for you. For these cases, you can use an api. Best of all, they should look and feel very familiar.
Was this page helpful?