validate([ "email" => "required|email", "password" => "required" ]); if (Auth::attempt(["email" => $credits["email"], "password" => $credits["password"]])) { $user = Auth::user(); return response()->json([ "account" => $user->name, "redirect" => "3000", "message" => "Login successful. Redirecting in 3 seconds..." ], 200); } return response()->json(["error" => "Invalid email or password."], 401); } catch (\Illuminate\Validation\ValidationException $exception) { return response()->json(['error' => $exception->errors()], 422); } catch (\Exception $exception) { return response()->json(['error' => 'An unexpected error occurred.'], 500); } } }