K
Kinde3mo ago
Hundrick

Error : Moved Permanently POST /api/kinde-webhook 400

Hi, I'm currently trying to implement a Webhook with Kinde in order to sync The Kinde Users with my DynamoDB database. I used this command for dev testing :
ngrok http http://localhost:3000
ngrok http http://localhost:3000
I changed the URL Webhook in Kinde to the URL generated by nGrok. With that tool I can see the JWT but I encountered this error : Moved Permanently POST /api/kinde-webhook 400. And I have no idea what's wrong... Here's my api/kinde-webhook/route.ts file.
10 Replies
Hundrick
HundrickOP3mo ago
Here's the Webhook setting in Kinde
No description
Roshan
Roshan3mo ago
Hi Hundrick,
Thanks for the detailed info and screenshots, that really helps.

https://6b1681308703.ngrok-free.app/api/kinde-webhook

Based on this and the error Moved Permanently POST /api/kinde-webhook 400, here’s a quick analysis and some next steps:

Observations: 1. Webhook Path Looks Correct
Your endpoint URL in the Kinde dashboard matches the ngrok URL + /api/kinde-webhook, which looks good. 2. Next.js App Routing Issue Possible
The “Moved Permanently” error (likely HTTP 308) usually indicates a redirect , often caused by: - A missing trailing slash in the request when the framework expects one (or vice versa). - Misconfigured route file in the App Router. 3. 400 Bad Request
Your handler returns 400 when the JWT is invalid or verification fails, which may be expected if the request is being redirected or malformed before reaching your logic.
Roshan
Roshan3mo ago
1. Recommendations: 1. Test with a Minimal Handler To confirm your webhook is even hitting the endpoint (before decoding JWT), temporarily replace your handler with:
import { NextResponse } from "next/server";
import { NextResponse } from "next/server";
export async function POST(req: Request) {
export async function POST(req: Request) {
console.log("Webhook received");
console.log("Webhook received");
return NextResponse.json({ message: "ok" });
return NextResponse.json({ message: "ok" });
}
}
Then trigger the webhook again via the “Send test event” in the Kinde UI and check your terminal logs. 2. Check File Placement and Server Running Ensure: - The route.ts is located exactly at:
app/api/kinde-webhook/route.ts (not pages/api) - Your dev server is running locally via npm run dev or yarn dev. - The ngrok tunnel is started after your local server is running. 3. Try with Trailing Slash Some frameworks treat /api/kinde-webhook and /api/kinde-webhook/ differently. You can try updating the Kinde webhook URL to:
https://6b1681308703.ngrok-free.app/api/kinde-webhook/
https://6b1681308703.ngrok-free.app/api/kinde-webhook/
Sometimes this prevents an implicit redirect (HTTP 308) that Next.js might trigger depending on the route handler config. 4. Ensure No Middleware/Auth on Webhook Path Confirm that the /api/kinde-webhook route is not protected by any middleware, authentication wrapper, or headers check. Kinde must be able to call this route unauthenticated. We’re attempting to replicate this setup internally as well. While we do that, feel free to: - Replace the handler with a minimal logging version. - Test triggering the webhook via the UI. - Let us know if you see "Webhook received" in your terminal, that will confirm if the request is reaching your code or being redirected before it hits. Thanks again for your patience while we dig into this!
Kinde docs
Add and manage webhooks
Our developer tools provide everything you need to get started with Kinde.
Hundrick
HundrickOP3mo ago
1. Test with a Minimal Handler : the console log and the NextResponse.json work great. ✅ 2.Check File Placement and Server Running ✅ 3.Try with Trailing Slash : Kinde won't let me do that, the "/" at the end is an error for him. ❌ 4. Ensure No Middleware/Auth on Webhook Path : I already allowed api/kinde-webhook as a public route as you can see ✅
Hundrick
HundrickOP3mo ago
It's seems that the issue is inside my logic Because the solution 1 works
Hundrick
HundrickOP3mo ago
No description
Hundrick
HundrickOP3mo ago
It seems that the error comes from this line
Hundrick
HundrickOP3mo ago
But this ligne comes from your documentation : https://docs.kinde.com/integrate/webhooks/webhooks-nextjs/ Is the code outdated ?
Kinde docs
Set up webhooks using Next.js
Our developer tools provide everything you need to get started with Kinde.
Hundrick
HundrickOP3mo ago
Oh I found the error it's so stupid... I wrote
KINDE_ISSUER_URL=https://trostock.kinde.com/
KINDE_ISSUER_URL=https://trostock.kinde.com/
instead of
KINDE_ISSUER_URL=https://trostock.kinde.com
KINDE_ISSUER_URL=https://trostock.kinde.com
So here the code wasn't happy :
const client = jwksClient({
jwksUri: `${process.env.KINDE_ISSUER_URL}/.well-known/jwks.json`,
const client = jwksClient({
jwksUri: `${process.env.KINDE_ISSUER_URL}/.well-known/jwks.json`,
Thank you help and your time !
Roshan
Roshan3mo ago
Hi Hundrick,

You're absolutely welcome, and no worries at all! That trailing slash mistake is super easy to miss, especially when working with environment variables and URL construction. Glad you caught it , great debugging!

Did you find this page helpful?