Handling CORS
cors
library along with getCORSAllowedHeaders
function: API Reference
Use the npm getCORSAllowedHeaders()
returns an array of headers that is used by SuperTokens. These need to go in theAccess-Control-Allow-Headers
header.- You'll also need to use
Access-Control-Allow-Credentials
andAccess-Control-Allow-Origin
The above can be achieved easily via the cors
library as seen below
Example
let SuperTokens = require("supertokens-node");
let express = require("express");
let cors = require("cors");
let app = express();
app.use(
cors({
origin: "http://127.0.0.1:8080",
allowedHeaders: ["content-type", ...SuperTokens.getCORSAllowedHeaders()],
methods: ["GET", "PUT", "POST", "DELETE"],
credentials: true,
})
);