Skip to content

Q: Get config from route in middleware? #2789

Open
@testersen

Description

@testersen

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions