Reputation: 1
ok, I've been using inertiaJs for a little over 1 year, only it's as if inertia can no longer receive data from the backend.
for example, here's the simple authentification form I send:
const handleSubmit = (values) => {
router.post(route('instance.login', { as: as }), values, {
errorBag: “errors”,
onStart: (visit) => {
setLoading(true);
},
onSuccess: (successful) => {
console.log(successful);
},
onError: errors => {
console.log(errors)
},
onFinish: (visit) => {
setLoading(false);
},
});
};
values here is a simple json :
{
email: “[email protected]”,
email:MyPasswordForTest00,
remember:true,
}
now on the backend :
public function Login(Request $request, $as)
{
$credentials = $request->validate([
email' => ['required', 'email'],
password' => ['required'],
]);
if (Auth::attempt($credentials, $request->remember)) {
$request->session()->regenerate();
return redirect()->intended('dashboard');
}
return back()->withErrors('message', 'password incorrect');
}
when I execute a dd() , I see that I'm in the right method the problem is that
->withErrors()
I have already tried to :
const { errors } = usePage().props;
useEffect(() => {
if (errors) {
Object.keys(errors).forEach((key) => {
message.error(errors[key]);
});
}
console.log(errors)
}, [errors]); // here is still empty :(
the error pocket is still empty and I'm not redirected :_(
Upvotes: 0
Views: 13