Skip to content

Q: Get config from route in middleware? #2789

Closed
@jamesbradlee

Description

@jamesbradlee

Is it possible to define some config in a route:

// routes/authenticated-page.tsx
export const config = {
  auth: {
    roles: ["admin", "viewer"]
  }
}

export default function MyPage(){
  return <h1>hello</h1>;
}

And in a middleware, get that config?

// routes/_middleware.tsx
export const handler: MiddlewareHandler = async (request, context) => {
  if (context.routeConfig?.auth?.roles) {
    await ensureUserHasRoles(context.routeConfig.auth.roles)
  }
  return await context.next();
}

I can see that the application's configuration is in the context, but not the routes'. However, I do see that the destination is set to either static or route.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions