0

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 :

  • change the inertia middleware, it has no effect, in the client:

  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 :_(

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.