Skip to content

After version 0.17.2, on netlify, Authkit always throws: You are calling 'withAuth' on a route that isn’t covered by the AuthKit middleware #229

@spookyuser

Description

@spookyuser

Describe the bug
A clear and concise description of what the bug is.

On I think any version after 0.17.2 but certainly above 1.0, If you call withAuth in a server component like so:

export default async function DashboardLayout({
  children
}: {
  children: React.ReactNode
}) {
  const auth = await withAuth({
    ensureSignedIn: true
  })

  return (
    <Providers userId={auth.user?.id}>
      <div className="h-[calc(100vh+2.75rem)]">

On netlify, Authkit will always throws this error:

`Error: You are calling 'withAuth' on a route that isn’t covered by the AuthKit middleware. Make sure it is running on all paths you are calling 'withAuth' from by updating your middleware config in 'middleware.(js|ts)'

When running locally it doesn't happen.

To Reproduce
Steps to reproduce the behavior:

Run the authkit nextjs example on netlify with an rsc component

Expected behavior
A clear and concise description of what you expected to happen.

I expect to be able to call withAuth in server components like in 0.17.2 on netlify

Desktop (please complete the following information):

  • OS: macos
  • Browser chrome
  • authkit-nextjs version 2.2.0
  • Next.js version 15.2.3

Additional context
I think it could be related to this issue https://answers.netlify.com/t/nextjs-headers-set-in-middleware-not-available-on-layout-tsx-or-page-tsx/129098

Also if this is something netlify needs to fix that's totally fair

Also I think the key difference is here https://github.com/workos/authkit-nextjs/blame/1a6649e302fc24a112171c9c827d069c82b610fb/src/session.ts#L106 I think in 0.17 the headers were adjusted in the request not response by the middleware

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions