I have a problem, I’m developing a web page which is made up of a server and a client.
Server: It’s a restful API with expressjs. I have a route there
//* @route GET api/auth/
Which helps me log in to Google, from Postman it’s possible, but the problem is when I access it with Axios from my client (Vue) and it shows me the error:
Access to XMLHttpRequest at ‘https://accounts.google.com/o/oauth2/v2/auth?…..’
(redirected from ‘http://localhost:5173/api/auth/’) from origin ‘http://localhost:5173’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
VM554:1 Login with Google failed
AxiosError {message: ‘Network Error’, name: ‘AxiosError’, code: ‘ERR_NETWORK’, config: {…}, request: XMLHttpRequest, …}
In my index.js (from server)
const cors = require(‘cors’)
const corsOptions ={
origin:’*’,
credentials:true,
optionSuccessStatus:200,
}
app.use(cors(corsOptions))
An idea to solve my problem