我有一个安装了 Next-Auth 的 NextJS 前端和一个使用 Sanctum 的 Laravel 后端当我尝试使用 Next-Auth 的登录功能登录时,它给了我这个错误:
Request failed with status code 419
Run Code Online (Sandbox Code Playgroud)
419 与 CSRF 令牌有关,但我在调用登录方法之前通过调用 sainttum/csrf-cookie 路由来设置令牌
[...nextauth.js]
Request failed with status code 419
Run Code Online (Sandbox Code Playgroud)
apiClient.js
CredentialsProvider
({
name: 'Email and Password',
credentials: {
email: {label: "Email", type: "email", placeholder: "Your Email"},
password: {label: "Password", type: "Password"}
},
async authorize({email, password}, req) {
await apiClient.get("/sanctum/csrf-cookie");
const user = await apiClient.post('/customer/login', {
email: email,
password: password,
});
if (user) {
return user
} else {
return …
Run Code Online (Sandbox Code Playgroud) 我没有使用"form"标签创建了这种形式
我需要在Hello ____之间的警报框中添加一个中断.您的电子邮件地址是:.是否可以这样做?我试过br标签和\n但似乎什么都没有用
<head>
<title>Welcome Sheet</title>
</head>
<body>
<h1> Form Details</h1>
Run Code Online (Sandbox Code Playgroud)
名字
<br>
<input type="text" id="fname" placeholder="eg.John">
<br><br>
Run Code Online (Sandbox Code Playgroud)
姓
<br>
<input type="text" id="lname" placeholder="eg.Doe">
<br><br>
Run Code Online (Sandbox Code Playgroud)
电子邮件地址
<br>
<input type="email" id="email" placeholder="eg.johndoe@example.com">
<br><br>
<button onclick="myFunction()">Submit</button>
<script>
function myFunction() {
alert("Hello" + " " + document.getElementById("fname").value+ " " + document.getElementById("lname").value +" "+ "Your email address is:" + " " + document.getElementById("email").value);
}
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
alert ×1
csrf-token ×1
css ×1
function ×1
html ×1
javascript ×1
laravel ×1
next-auth ×1
next.js ×1