I developed a react app and a express API. Everything were working correctly in localhost.
I moved my API to digitalocean droplet which is only IP address and it's HTTP.
When I use API from react app in development environment, it's working. It's getting cookies from API, sending them to API for authorization...
But, after I run npm run build
on my react app for production and serve it on my local computer, It's stopped to send cookies to API and API stopped send cookies to react app anymore.
I set my API's IP as base url and credential true in index.js / react app
axios.defaults.baseURL = "http://xxx.xxx.xxx.xxx"
axios.defaults.withCredentials = true
API cors settings in API
app.use(cors({origin: true, credentials: true}))
Axios login request (no cookies shows up after succesfull login)
await axios.post('/api/main/login', {form: form}).then(async resp => {
if(resp.data == 'VALIDERR' || resp.data == 'CHECKERR') {
setErrs({...errs, serverErrs: [resp.data]})
setLoading(false)
} else {
setLoading(false)
checkLogin()
window.location.href = "/admin"
}
})
API's res.cookie for login request
res.cookie('auth', {token: token, name: user.name}).send('OK')
I hope someone have an idea what's going wrong after building react app. Thanks for your help