Hello, I try to use the Realm Administration API and this is the function for getting the token.
async function cloudLogin() {
const response = await fetch(
"https://realm.mongodb.com/api/admin/v3.0/auth/providers/mongodb-cloud/login",
{
method: "POST",
headers: {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json",
},
body: JSON.stringify({
username: "<Public API Key>",
apiKey: "<Private API Key>",
}),
}
);
const json = await response.json();
console.log(json);
}
The error I get is
Access to fetch at 'https://realm.mongodb.com/api/admin/v3.0/auth/providers/mongodb-cloud/login' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
As the message suggests to add ‘no-cors’ I also tried this but then I get this
Uncaught (in promise) SyntaxError: Unexpected end of input
this line > const json = await response.json();
Doing a curl works but with fetch no chance, does anyone see the issue here? I allowed my current IP Address and I do the fetch from localhost:3000
Thanks