提交登录表单后,我收到“密钥“_username”必须是字符串,给出“NULL””
这是我的jsx:
fetch('/signin', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: JSON.stringify({
_username: "[email protected]", // Test email
_password: "your_password" // Test password
})
})
.then((res) => res.json())
和我的控制器:
#[Route('/signin', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('app_dashboard');
}
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->json([
'last_username' => $lastUsername,
'error' => $error ? $error->getMessage() : null,
]
和我的 security.yaml
form_login:
login_path: /signin
check_path: /signin
enable_csrf: true
secure: auto
你能帮我吗
您只需使用 JSON 登录即可使用 API 进行登录,