护照没有设置饼干
如果我在Localhost中打开Express和React Server,则效果很好。但是,如果我在AWS(HTTP)中打开Express Server,则未设置Cookie。
这是我的Express index.ts代码。
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(
session({
secret: sessionSecret,
resave: false,
saveUninitialized: false,
cookie: {
secure: false,
sameSite: "none",
},
})
);
app.use(cors({ origin: frontendOrigin, credentials: true }));
app.use(passport.initialize());
app.use(passport.session());
app.use("/", router);
app.listen(8000, () => {
console.log("Server has been started...");
});
我尝试删除cookie
在Express-Session中的选项,Origin:true
和onement:False
CORS中的false 。
我喜欢这样的
const res = await fetch(`${backend}/api/profile`, {
credentials: "include",
});
原因,为什么它只能在Localhost中起作用? OFC我打开了AWS端口8000。
if i open express and react server in localhost, it works well. but if i open express server in aws(http), the cookie is not set.
here is my express index.ts code.
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(
session({
secret: sessionSecret,
resave: false,
saveUninitialized: false,
cookie: {
secure: false,
sameSite: "none",
},
})
);
app.use(cors({ origin: frontendOrigin, credentials: true }));
app.use(passport.initialize());
app.use(passport.session());
app.use("/", router);
app.listen(8000, () => {
console.log("Server has been started...");
});
i tried remove cookie
options in express-session, origin: true
and origin: false
in cors.
and i fetch like this
const res = await fetch(`${backend}/api/profile`, {
credentials: "include",
});
why it only works in localhost? ofc i opened aws port 8000.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论