Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
37 replies
Børge

Cors error

Hello, I keep getting a cors error when trying to logout in my application. Im using nextjs on the frontend, and have a different express backend. I'm pretty new, and cant really tell whether it's coming from the backend or the frontend

Frontend: localhost:3000
Backend: localhost:3030

Error:
Access to XMLHttpRequest at 'http://localhost:3000/' (redirected from 'http://localhost:3030/v1/auth/discord/logout') 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.


On the express backend, I have set up cors options like this:
var corsOptions = {
    origin: "http://localhost:3000",
    credentials: true,
    optionSuccessStatus: 200,
};

app.use(cors(corsOptions));


And this is the logout function from the backend:
export async function logout(req: Core.Request, res: Core.Response): Promise<(Core.Response | void | undefined)> {
    return res.clearCookie("access_token").redirect("http://localhost:3000")
}   


Does anyone know how to fix the error?
Was this page helpful?