【发布时间】:2022-08-23 23:18:50
【问题描述】:
我看到了许多类似的问题,并尝试了许多组合,但没有任何效果。 我指定它都在本地主机上。
regUser = () => {
var username = getE(\"username-input\").value;
var email = getE(\"email-input\").value;
var password = getE(\"password-input\").value;
axios({
url: process.env.REACT_APP_API_URL + \"register\",
method: \"post\",
data: {
username, email, password
},
withCredentials: true
}).then(res => {
if(res.data.regSuccess) {
// Registration successful
this.setState({
regSuccess: true,
regTextHidden: false,
regText: \"Registration Successful! An e-mail was sent to the specified e-mail address with confirmation information! You will be redirected to the Login page...\"
}, ()=>{
setTimeout(
()=>{window.location.href=(\"/login\")}, 5000
)
})
} else {
this.setState({
regSuccess: false,
regTextHidden: false,
regText: \"An error occured. Please try again later!\"
})
}
})
}
后端代码:
f.checkPassword(userData, function(result) {
if(!result.correct) {
// Wrong password
res.send({found: true, correct: false})
} else {
// Proceed with authentication
var token = f.genToken(userData.user);
res.header(\"OPTIONS\", \'true\')
res.cookie(\"access-token\", token.token, {httpOnly: true, sameSite: \"none\", maxAge: \"100000\", secure: false});
res.send({found: true, correct: true})
}
})
无论我使用什么 cookie 设置,它们都会被发送,\"Set-Cookie\" 标头存在,但没有设置 cookie。
我已经使用每个选项玩了 2 天,但它只是不起作用。有什么建议吗?
-
尝试了所有答案,但没有一个有效:(
-
编辑:我累了,我试图在反应中编辑一个不同的请求......它有效!
标签: reactjs express cookies localhost