Tito
Tito
KKinde
Created by Tito on 2/15/2025 in #💻┃support
Gateway timeout for Management API
i had 504 gateway time out errors for about an hour and then it solved itself
5 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
Thank you, it works now. Notice that in https://github.com/kinde-oss/management-api-js, you should change the docs in Configuration KINDE_DOMAIN e.g. https://mybusiness.kinde.com as the https:// is required. I would call it KINDE_URL.
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
Actually I had to revert it back because there is a chain reaction of other Next packages that can't be imported any more. I can't import management-api-js because it creates some sort of confusion between ES module and CommonJS module.
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
But the issue is still that Module '"@kinde/management-api-js"' has no exported member 'Users'.
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
i also had to add "type": "module" to package.json
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
The problem was maybe related to the fact that I initially started by NextJS backend app by editing [email protected] which defines a next.config.js with require syntax instead of import
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
Three outstanding issues for me: - I can extract user info using m2m from backend, but I don't think the JWT token is "Verified". How do I verify validity of the token from the backend? - I couldn't figure out how to have a long-lived access token for the M2M api, i only see references to "test-tokens" - I can't import management-api-js due to an error (see above), for now I am just using REST API directly
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
For posterity, this is how I call Kinde Management APIs from a NextJS backend, given a user's accessToken (originally obtained by having the user login on an expo react native app):
export async function getKindeUserByAccessToken(accessToken: string): Promise<KindeUser | null> {
try {
// Decode the JWT token (it's base64 encoded)
const [, payload] = accessToken.split('.');
const decodedPayload = JSON.parse(Buffer.from(payload, 'base64').toString());
const kindeId = decodedPayload.sub;

if (!kindeId) {
throw new Error('No sub claim found in access token');
} else {
console.debug(`[kinde] Found Kinde ID ${kindeId} in access token`);
}

// Fetch the full user details using the Kinde ID
const userResponse = await fetch(
`${process.env.KINDE_ISSUER_URL}/api/v1/user?id=${kindeId}`,
{
headers: {
Authorization: `Bearer ${process.env.KINDE_API_KEY}`,
Accept: "application/json",
},
}
)

if (!userResponse.ok) {
const json = await userResponse.json();
console.warn(`[kinde] Failed to fetch Kinde user: ${userResponse.statusText}:\n`, json);
return null;
}

const userData = await userResponse.json()
return userData;
} catch (error) {
console.error("Error fetching Kinde user by access token:", error)
return null
}
}
export async function getKindeUserByAccessToken(accessToken: string): Promise<KindeUser | null> {
try {
// Decode the JWT token (it's base64 encoded)
const [, payload] = accessToken.split('.');
const decodedPayload = JSON.parse(Buffer.from(payload, 'base64').toString());
const kindeId = decodedPayload.sub;

if (!kindeId) {
throw new Error('No sub claim found in access token');
} else {
console.debug(`[kinde] Found Kinde ID ${kindeId} in access token`);
}

// Fetch the full user details using the Kinde ID
const userResponse = await fetch(
`${process.env.KINDE_ISSUER_URL}/api/v1/user?id=${kindeId}`,
{
headers: {
Authorization: `Bearer ${process.env.KINDE_API_KEY}`,
Accept: "application/json",
},
}
)

if (!userResponse.ok) {
const json = await userResponse.json();
console.warn(`[kinde] Failed to fetch Kinde user: ${userResponse.statusText}:\n`, json);
return null;
}

const userData = await userResponse.json()
return userData;
} catch (error) {
console.error("Error fetching Kinde user by access token:", error)
return null
}
}
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
And:
"@kinde-oss/kinde-auth-nextjs": "^2.3.10",
"@kinde/management-api-js": "^0.11.0",
"@kinde-oss/kinde-auth-nextjs": "^2.3.10",
"@kinde/management-api-js": "^0.11.0",
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
Using npm 10.1.0, react 18.2.0, next 14.1.0
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
i don't have the issue with the other kinde packages
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
i played around, i can't use this management-api-js module, not sure if the npm package is the latest version
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
Cursor warning on the import statement
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@kinde/management-api-js")' call instead. To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field "type": "module" to '/Users/.../streckenheldnext/package.json'.
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
but how do i get a server-to-server token that lasts longer than an hour?
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
docs always talk about "test token"
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
thanks ok
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
I am now facing the question of how to get a long-lived token for the M2M application. I initially struggled because my token had expired
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
I managed. This should be a very common use case that could be documented or have some utility libraries to actually use it.
61 replies
KKinde
Created by Tito on 2/3/2025 in #💻┃support
Authenticating API calls with Kinde
Thanks. I previously managed to use M2M API to get a user by email. How do I get users details given an accessToken?
61 replies