Hi, I need help with a development to get an authorization token for my user CRUD. I am removing a user first from auth0 and then from my database(with a try catch) but for that I need the authorization token and I am passing it manually because I am having problems to get it with the API. My current code with the jwt set manually:
export const deleteUser = async (id) => {
try {
const auth0Endpoint = `https://dev-domain.us.auth0.com/api/v2/users/auth0|${id}`;
const auth0Headers = new Headers();
auth0Headers.append("Authorization", `Bearer MyAccessTokenHardcoded`);
const requestOptions = {
method: 'DELETE',
headers: auth0Headers,
redirect: 'follow'
};
// Realiza la solicitud de eliminaciĂłn en Auth0
const auth0Response = await fetch(auth0Endpoint, requestOptions);
// Verifica si la eliminaciĂłn en Auth0 fue exitosa
if (auth0Response.status === 204) {
// Si la eliminaciĂłn en Auth0 fue exitosa, elimina el usuario en tu base de datos
const response = await interceptor.delete(`/${id}`);
return response.data;
} else {
console.log('Error al eliminar usuario en Auth0:', auth0Response.statusText);
}
} catch (error) {
console.log(error);
}l
};
This works but it is not efficient to have to keep updating my token. The token that is working for me is in: Api’s → Auth0 Managment Api → Api explorer
Hey @tyf!
Thank you for guiding me on this path. I am looking at the links that you just send me. They are very useful.
My problem is that I am not using a backend for auth0. Everything is in my React application and when I want to get the token I get some errors in the request usually status 500. I already activated the cors in my application panel. I don’t know if I need to create a different api to request this token from my application or if I can request the default “Auth0 Management API”.