I am working on building an Internet Switch with Grandeur Cloud and following the tutorial on hackster. I am running the example provided but it is giving me Blocked by CORS policy
error. The code snipped is attached as below
/*
@file: main.js
Initialize the SDK and get
a reference to the project
*/
var apolloProject = apollo.init("YOUR-API-KEY", "YOUR-ACCESS-KEY", "YOUR-ACCESS-TOKEN");
/*
Function to login user
we creating while getting started
*/
async function login() {
/* Store credentials into variables */
var email = "EMAIL";
var password = "PASSWORD";
/* Set the status to logging in */
document.getElementById("status").innerText = "Logging in";
/* Then get a reference to auth class */
var auth = apolloProject.auth();
/* and in a try catch block */
try {
/* Submit request using login function */
var res = await auth.login(email, password);
/*
Got the response to login
handle response
*/
switch(res.code) {
case "AUTH-ACCOUNT-LOGGEDIN":
case "AUTH-ACCOUNT-ALREADY-LOGGEDIN":
/*
User Authenticated
Set the status to success
*/
document.getElementById("status").innerText = "User Authenticated";
break;
default:
/*
Logging failed due
to invalid data
*/
document.getElementById("status").innerText = "Authentication Failed";
}
}
catch(err) {
/*
Error usually got generated when
we are not connected to the internet
*/
document.getElementById("status").innerText = "Network Error";
}
}
/* Call login on startup */
login();
What I am possibly doing wrong?
Note: I have reviewed the suggestions given, but it is not about the generic CORS error. It is a platform specific question. Grandeur Cloud is a BaaS platform for IoT and I am using it as backend for my app and hardware. So you can whitelist the allowed domain but I don't know how to do that.