Error status 400

Hello,
I’m a totorial user and I’m stuck on the payment plan. I don’t understand the problem. When I click on my plan, I get this error message.

Do you have any ideas?

Thank you for your help.

The request to /api/checkout is failing with a 400 error, which likely means the server isn’t receiving the data it expects.

The first thing to check is what your browser is sending to the backend. To do this go to the “Network” (Réseau) tab in the dev tools, then click the button to trigger a request. Look for the request to /api/checkout in the list, then click on it. In the details pane, check the “Headers” (En-têtes) and “Payload” (Charge utile) sections. Under “Payload”, confirm that all expected data is being sent — for example, plan name, user ID, or anything your backend expects. Also check the “Response” (Réponse) tab to see if there’s a message giving more info about what went wrong.

If that doesn’t give you any clues, still under “Headers” ensure you’re sending the correct Content-Type, especially application/json if you’re posting JSON. And in your /pages/api/checkout.js file, add a console.log(req.body) to see exactly what the backend receives when the button is clicked.

Also make sure any required environment variables (like API keys) are correctly set in your .env.local file and available to your backend.

Let us know how that goes (and sorry for my bad French).

2 Likes

Thank you for your reply.
When I click on a plan, I get the message “invalid plan.”
I checked my .env file and it’s correct.
However, I see that I don’t see any recordings in my Neon console, even though that should be the problem. I don’t know where to check this.

The “invalid plan” message probably means that the backend can’t find the user or match a user to the plan correctly.

Since your Neon console shows no entries in the Profil table, it looks like no user data is being saved. That could be why the plan can’t be validated.

To check this: go to your Neon Console, open your database, then click on the Profil table (as you have done). If it’s empty, that confirms no user records exist yet. If this is the case, you will need to check where users are supposed to be created in your app and make sure that’s working.

1 Like

Regarding the API key, it’s correct, however, I see that in Production it displays the tables but no records and in Development there is nothing, no tables, is that normal?

Nope, that doesn’t sound normal. It sounds like your production and development environments are using different Neon branches or databases. Make sure both environments point to the correct database in your .env.local, and confirm your app is connecting to the same branch where your tables and data exist.

1 Like

in my .env file I have indicated the path:

DATABASE_URL="postgresql://neondb_owner:npg_xxxxxxxxxxxxxx@xxxxxxxx-pooler.us-east-1.aws.neon.tech/neondb?sslmode=require"

and in my .env.local file:

NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_xxxxxxxxxxxlcmsuYWNjb3VudHMuZGV2JA
CLERK_SECRET_KEY=sk_test_TxvxvDWns5Vxxxxxxxxxxxxxxxxxxxxxx

When I log in to register, everything goes well, but I see that it does not add the data in Neon.

It looks like your local environment may not be using the DATABASE_URL, since from what I’m understanding, it’s only defined in .env and not in .env.local.

When running the app locally, .env.local should take priority, so it’s possible your backend isn’t connected to the Neon database, or it’s connecting to the wrong branch.

Could you check if DATABASE_URL is also present in your .env.local file? If not, that might explain why no data is showing up in Neon during development.

1 Like

I think this is correct? Here are my two files.

file .env

DATABASE_URL="postgresql://neondb_owner:xxxxxxxxxxx@ep-cold-shape-a4evj9p6-pooler.us-east-1.aws.neon.tech/neondb?sslmode=require"

file .env.local

NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_cG9zc2libGUtYXJhYxxxxxxxxxlcmsuYWNjb3VudHMuZGV2JA
CLERK_SECRET_KEY=sk_test_TxvxvDWns5VCwOC3VKnjaEhE8xxxxxxxxxxxxx

Your .env.local file only includes your Clerk keys, but it’s missing the DATABASE_URL. Unless I’m missing something obvious, this means your backend has no connection to Neon when you’re running the app locally.

This would also explain why login works (Clerk handles that), but no data gets saved to your Neon database, as your app isn’t connected to it.

Can you try adding the same DATABASE_URL line from your .env file to .env.local, then restart your dev server and test again? Let us know how that goes.

1 Like

I added the DATABASE_URL line to the .env.local file, and I still get the “invalid plan” error message, and there’s still no data in Neon.
I’ll show you the tutorial link.
https://www.youtube.com/watch?v=RUE3nYI75VE

If you’re still getting the “invalid plan” error and no data is appearing in Neon, then it’s likely that your app is still not creating a user record in the database after login. Clerk handles authentication, but unless your app explicitly writes to the Profil table after someone signs up or logs in, the DB stays empty.

Check the part of the tutorial where the user is supposed to be inserted into the database — make sure that logic exists and is actually being triggered. You can add a console.log or DB log right after login to confirm it runs.

1 Like

Wouldn’t the problem be here?

Yeah, looks like Prisma can’t connect to Neon. Double-check your connection string and make sure the host and port are correct. Also, check that your Neon branch is awake. Until that’s fixed, nothing else in your app that depends on the database will work.

1 Like

Hello,

I’ve been looking for the problem since yesterday, and I don’t understand why it doesn’t make the connection.
Here are the screen prints, everything is good I think.
console neon

clerk

Neon and Clerk both look properly configured.

If Prisma still can’t reach the Neon database, maybe something local is blocking the connection. Could be a firewall, VPN, or network restriction etc?

If it were me, I’d strip everything back and build the smallest possible version of the app — just enough to connect to Neon and run one simple query — no auth, no extras, just to confirm the DB connection works.

Chances are that if you do that, you’ll find where the problem lies.

2 Likes

Your database maybe idle, and when you connect to it is trying to activate but before it can do it the connection timeout or the connection pool timeout. Follow this instruction from Prisma.

https://neon.tech/docs/guides/prisma#connection-timeouts

2 Likes