Kinde Management API - 400 Bad Request: malformed Host header
I am trying to create an Organization and move a user that's in the Default Organization into it using the Kinde Management API; however, I am getting the error:
I started by trying to enable Kinde Management API in the Kinde Console for my NextJS app but got the error:
"m2m applications can have access the kinde management api"
So I create a M2M application, added the following env variables:
7 Replies
I created a POST request in my NextJS app to create the org and move the user:
Can anyone see what I'm doing wrong?
Thanks for this @Kenton , let me check this out for you.
Hi @Kenton , I didn't spot immediately, the route is missing the
init
method, this is required to set the management SDK correctly. The aim is to have this auto configure however some frameworks his was problematic, hope to address in later releases.
Below is updated code, tested and working.
@Daniel_Kinde yesterday, I moved one of my users from the default org to a newly created org. What's surprising, is that the users orgCode in the active session didn't update to the new org the user was moved to but instead remained the same until the user session expired and the user logged back in again.
I presume I'll need to do a change session of some kind after creating the new org and moving the user to that org? Hopefully the user doesn't have to login again.
I'm following your conversations re. is_create_org. Would this be fixed with a token refresh?
Since moving the user to the new org is part of signup i.e they wouldn't have had to use the login page yet, I'm assuming a token refresh should hopefully be painless at signup?? Just found this re. refreshing token data:- https://discord.com/channels/1070212618549219328/1276004138785833052/1276004138785833052
Since moving the user to the new org is part of signup i.e they wouldn't have had to use the login page yet, I'm assuming a token refresh should hopefully be painless at signup?? Just found this re. refreshing token data:- https://discord.com/channels/1070212618549219328/1276004138785833052/1276004138785833052
yup! I think what we want here is to call
refreshTokens()
from getKindeServerSession
before returning the NextResponse
Something like:
Although you may want to have it inside the trycatch 😄What's the purpose of the refreshTokens?
The following works for me. create route /create-org
Create a /create-org page:
middleware.ts
This is all very hacky. Will clean it all up over the weekend so others can reuse it.
Peter, still interested in knowing the purpose of the refreshTokens in this flow.
hey @Kenton - the purpose of refreshTokens is to sync up the the tokens stored in the cookies with Kinde data. So if Kinde data is updated via the api, data will be changed on Kinde, but it wont be reflected in the tokens (in your app) unless you refreshTokens. Hope that made sense!