Typescript jwt payload type?
Hi there,
Just trying to implement a webhook and struggling a little with the types returned when verifying the jwt. I think it's the JwtPayload types? Sorry, I'm not too hot on JWTs!
Do I need the kinde-typescript-sdk? I could see anything in there that would help, but could've missed it!
Thanks!
Nick
4 Replies
Hi @Nick ,
Thank you for reaching out! I’d be happy to assist you with your webhook implementation.
To better understand your issue and provide the best guidance, could you clarify a couple of points?
1. Which Kinde SDK are you using? This will help us determine if the kinde-typescript-sdk is relevant to your implementation.
2. What are you trying to achieve with the JWT payload? Are you attempting to validate the token, extract specific claims, or something else entirely?
3. Are you looking for guidance on the structure of the JWT payload (e.g., claims or custom attributes) or how to handle it in your TypeScript code?
Once I have more details, I’ll do my best to point you in the right direction. Feel free to share any snippets of code or additional context that might help!
Looking forward to your response.
Best regards,
Ages
Sorry to hijack @Ages - @Nick you may be interested in this gist I created recently for validating and getting type inference on the Webhook payloads - https://gist.github.com/Yoshify/12e70d5a3bbc2c9ed66a4207d2d2e9cc
Gist
Kinde Webhooks + Zod
Kinde Webhooks + Zod. GitHub Gist: instantly share code, notes, and snippets.
Hi @Yoshify ,
No worries at all, please feel free to continue.
Sorry it's taken a while to respond, ended up in bed with a banging migraine yesterday!
@Ages I was just trying to get the compile time error on
event?.type
to go away. But I solved the issue (I think) by asserting that the result of jwt.verify was of type jwt.JwtPayload
.
Code snippet from the app/api/kinde-webhook/route.ts
route described here (https://docs.kinde.com/integrate/webhooks/webhooks-nextjs/)
I'm using the nextjs app router sdk, so I'm guessing the TS sdk isn't relevant?
Looks awesome, thanks!
Would you mind explaining the difference between using validateToken/jwtDecoder vs what's in the code above? (jwt.verify?)
Thanks again, had no idea the zod types would be so involved!