Closed kingRayhan closed 1 month ago
Hi @kingRayhan I would recommend switching to use @kinde/management-api-js.
We are updating our guidance on this away from the one inside the Next SDK See here: https://docs.kinde.com/developer-tools/sdks/backend/nextjs-sdk/#kinde-management-api
I tried to use that @kinde/management-api-js, but still got the credential error.
Would you please give me an idea of how to pass credentials?
import { Users } from "@kinde/management-api-js";
import { NextRequest } from "next/server";
export const POST = async (request: NextRequest) => {
try {
const { users } = await Users.getUsers();
return Response.json(users);
} catch (error) {
return Response.json({ error: error });
}
};
Response
{
"error": {
"url": "https://app.kinde.com/api/v1/users",
"status": 403,
"statusText": "Forbidden",
"body": {
"errors": [
{
"code": "INVALID_CREDENTIALS",
"message": "Invalid credentials used to access API"
}
]
},
"request": {
"method": "GET",
"url": "/api/v1/users",
"query": {},
"errors": {
"403": "Invalid credentials.",
"429": "Request was throttled."
}
},
"name": "ApiError"
}
}
I found the init()
function from @kinde/management-api-js library, I initialized but still now outputs going to the catch.
import { Users, init } from "@kinde/management-api-js";
import { NextRequest } from "next/server";
init({
kindeDomain: process.env.KINDE_ISSUER_URL!,
clientId: process.env.KINDE_CLIENT_ID,
clientSecret: process.env.KINDE_CLIENT_SECRET!,
});
export const POST = async (request: NextRequest) => {
try {
const { users } = await Users.getUsers();
return Response.json(users);
} catch (error) {
return Response.json({ error: JSON.stringify(error) });
}
};
Also, I enabled the application’s access from the Kinde Management API interface
Can you try setting the management specific ENV variables and ensuring you're using M2M application https://github.com/kinde-oss/management-api-js#configuration
@DanielRivers thanks man, finally works 😍
Prerequisites
Describe the issue
Basically, I want to create a signup API where I will create a separate organization for every user signed up. I planned to create an organization like this
<username>'s space
name. I was digging through documentation, I found thiscreateKindeManagementAPIClient
.It has lots of helpful methods for managing kinde management API. I attempted the way below but every time I got bad request. Maybe I am making some silly mistake.
Library URL
https://github.com/kinde-oss/kinde-auth-react
Library version
^2.2.11
Operating system(s)
macOS
Operating system version(s)
14.5 (23F79)
Further environment details
No response
Reproducible test case URL
https://github.com/kingRayhan/kinde-play-org
Additional information
No response