admin管理员组文章数量:1122832
I am using Session from Express-session to got cookies for Login and using CORS in backend server and deploy on Railway, and deploy frontend on Netlify. I have many API but the problem was /Login and /Me, /Login for got email & password, and /Me for got cookies from Express-session. For /Login is got status OK(200) but for /Me got status Unauthorized(401), if I use localhost for Frontend it runs normally but if I use from Netlify it happens
This Backend :
app.use(
session({
secret: "any",
resave: false,
saveUninitialized: true,
store: store,
cookie: {
expires: new Date(Date.now() + 86400000),
maxAge: 30 * 24 * 60 * 60 * 1000,
domain: "https://***lify.app",
httpOnly: true,
secure: true,
sameSite: "none",
},
})
);
app.use(
cors({
credentials: true,
origin: "https://***lify.app",
})
);
and this frontend
axios.defaults.baseURL = "https://***.up.railway.app";
axios.defaults.withCredentials = true;
export const LoginUser = createAsyncThunk(
"user/LoginUser",
async (user, thunkAPI) => {
try {
const response = await axios.post(
"https://***-production.up.railway.app/api/login",
{
email: user.email,
password: user.password,
},
{ withCredentials: true }
);
return response.data;
} catch (error) {
if (error.response) {
const message = error.response.data.msg;
return thunkAPI.rejectWithValue(message);
}
}
}
);
export const getMe = createAsyncThunk("user/getMe", async (_, thunkAPI) => {
try {
const response = await axios.get(
"https://***-production.up.railway.app/api/me",
{ withCredentials: true }
);
return response.data;
} catch (error) {
if (error.response) {
const message = error.response.data.msg;
return thunkAPI.rejectWithValue(message);
}
}
});
本文标签: reactjsCannot got cookies from Expresssession in different websiteStack Overflow
版权声明:本文标题:reactjs - Cannot got cookies from Express-session in different website - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303003a1931734.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论