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