-
Notifications
You must be signed in to change notification settings - Fork 280
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
Error: Clerk: auth() and currentUser() are only supported in App Router (/app directory). #1642
Comments
It looks like the error is fairly clear here. Did you try using |
https://clerk.com/docs/quickstarts/nextjs states to use currentUser() or auth() if I'm using the app router which is exactly what I'm doing. I thought getAuth() is for the pages router? If that's the case I am not using the pages router. |
@VaniaPopovic have you tried moving the userAuth file directly below the |
I tested your repro @VaniaPopovic (only changed to my dev keys) and I am not getting the error. The api/works route was returning a 500 error until I swapped to NextResponse.json. Anything in particular that needs doing to reproduce the error? |
Sorry for the delay in the reply, I was away on holidays. I have debugged this more, as I was developing on my mac machine without any issues. The problem arises only on a windows machine if this helps! |
Hi @VaniaPopovic. Can you let me know which version of Windows, and if you were using Windows directly for WSL and any other info you can provide? Thanks. |
We are still waiting on a reproduction here, just a small update! |
@VaniaPopovic @royanger @jescalan I'm facing the same error. I created a file under the /lib directory dedicated to API management. However, when attempting to leverage Clerk.js for user authentication, I'm consistently facing this error message. Also tried moving the file directly under /app directory and haven't been able to resolve the issue. import { auth } from "@clerk/nextjs";
import prismadb from "./prismadb";
export const incrementApiLimit = async () => {
const { userId } = auth();
if (!userId) {
return;
}
const userApiLimit = await prismadb.userApiLimit.findUnique({
where: { userId: userId }
});
if (userApiLimit) {
await prismadb.userApiLimit.update({
where: { userId: userId },
data: { count: userApiLimit.count + 1 },
});
} else {
await prismadb.userApiLimit.create({
data: { userId: userId, count: 1 },
});
}
}; |
Hi, the issue is happening on my machine with Windows 11 Version 10.0.22621 Build 22621 , not using WSL. Tested the same repo on my mac, and I get no problems. |
You can try out my fork aswell if you like https://github.com/VaniaPopovic/acme-corp
I get the following output
And just a blank Internal server error white page on the desktop |
@VaniaPopovic Are you sure this error is related to |
Related issue: vercel/next.js#52176 |
Hi @jescalan , I will close this issue in favour of opening a new one. Thanks |
This Clerk error is very annoying. I should have encountered this error during development, not in production. The problem is with the "src" folder; it makes Clerk think it's a page route |
The problem in my case was that at the bottom of my ssr client.
|
Brief Summary of the Issue
Clerk is complaining about the usage of currentUser in app router.
I have extracted a common auth function under /lib/auth.
snippet of it can be found here:
When I import it in to a Apps Dir route handler I get the following error:
Minimal Reproduction or Replay
A reproduction of the repo can be found at : https://github.com/VaniaPopovic/clerk_repro
Browser/OS
Chrome 116.0.5845.111
,Node 19.8.1
,Package + Version
@clerk/clerk-js
@clerk/clerk-react
@clerk/nextjs
4.23.3@clerk/remix
@clerk/types
3.50.0@clerk/themes
@clerk/localizations
@clerk/clerk-expo
@clerk/backend
@clerk/clerk-sdk-node
@clerk/shared
@clerk/fastify
@clerk/chrome-extension
gatsby-plugin-clerk
build/tooling/chore
The text was updated successfully, but these errors were encountered: