Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: Get config from route in middleware? #2789

Open
testersen opened this issue Dec 11, 2024 · 0 comments
Open

Q: Get config from route in middleware? #2789

testersen opened this issue Dec 11, 2024 · 0 comments

Comments

@testersen
Copy link

testersen commented Dec 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant