Skip to content

Commit

Permalink
fix(nextjs): Warn about misplaced middleware file when using auth or …
Browse files Browse the repository at this point in the history
…getAuth

For NextJS 13 application, if the `/src` directory is used then the middleware file needs to be nested under it, otherwise the middleware will not run.

This is a very common user error - this commit updates the error message to list moving middleware under /src as a potential fix.
  • Loading branch information
nikosdouvlis committed Oct 17, 2023
1 parent 1ffb41e commit e2b507c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/nextjs/src/server/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ Alternatively, you can set your own ignoredRoutes. See https://clerk.com/docs/ne
`;

export const getAuthAuthHeaderMissing = () =>
'You need to use "authMiddleware" (or the deprecated "withClerkMiddleware") in your Next.js middleware file. You also need to make sure that your middleware matcher is configured correctly and matches this route or page. See https://clerk.com/docs/quickstarts/get-started-with-nextjs';
`Clerk: auth() was called but it looks like you aren't using authMiddleware in your middleware file. Please ensure the following:
- Use "authMiddleware" (or the deprecated "withClerkMiddleware").
- Make sure your middleware matcher is configured correctly and it matches this route or page.
- If you are using the /src directory, ensure that the middleware.ts file is located under it.
For more details, see https://clerk.com/docs/quickstarts/get-started-with-nextjs.
`;

export const authAuthHeaderMissing = () =>
"Clerk: auth() was called but it looks like you aren't using `authMiddleware` in your middleware file. Please use `authMiddleware` and make sure your middleware matcher is configured correctly and it matches this route or page. See https://clerk.com/docs/quickstarts/get-started-with-nextjs";
`Clerk: auth() was called but it looks like you aren't using authMiddleware in your middleware file. Please ensure the following:
- Use authMiddleware in your middleware file.
- Make sure your middleware matcher is configured correctly and it matches this route or page.
- If you are using the /src directory, ensure that the middleware.ts file is located under it.
For more details, see https://clerk.com/docs/quickstarts/get-started-with-nextjs.
`;

export const clockSkewDetected = (verifyMessage: string) =>
`Clerk: Clock skew detected. This usually means that your system clock is inaccurate. Clerk will continuously try to issue new tokens, as the existing ones will be treated as "expired" due to clock skew.
Expand Down

0 comments on commit e2b507c

Please sign in to comment.