Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Stephan_P's avatar

419 (unknown status)

I can't solve that error. I can register at regres.in (postman an with fetch), and I can register in my laravel sanctum API with postman. But when I trie with fetch I get this 419(unknown status) and SyntaxError: Unexpected token < in JSON at position 0.

my fetch looks like this:

const url = "http://localhost:9000/api/register";
const myForm = document.querySelector("#loginForm");

myForm.addEventListener("submit", async (e) => {
  e.preventDefault();
  const formData = new FormData(myForm);
  const formDataSerialized = Object.fromEntries(formData);
  const jsonObj = { ...formDataSerialized };

  try {
    const response = await fetch(url, {
      method: "POST",
      body: JSON.stringify(jsonObj),
      headers: {
        "Content-Type": "application/json",
      },
    });
    const json = await response.json();
    console.log(json);
  } catch (e) {
    console.error(e);
  }
});

and my Route(public):

Route::post('/register', [AuthController::class, 'register']);

wich is:

    public function register(Request $request){
        $fields = $request->validate([
        'name' => 'required|string',  
        'email' => 'required|string|unique:users,email',
        'password' => 'required|string|confirmed',
        ]);

        $user = User::create([
        'name' => $fields['name'],
        'email' => $fields['email'],
        'password' => Hash::make($fields['password']),
        ]);

        $token = $user->createToken('myapptoken')->plainTextToken;

        $response = [
            'user' => $user,
            'token' => $token
        ];

        return response($response, 201);
    }

at the end my form looks:

    <form action="#" id="loginForm">
      <label for="name" class="form-label">Your Name</label>
      <input
        type="text"
        class="form-control"
        id="name"
        name="name"
        placeholder="Ihr Name"
        autocomplete="off"
        autocapitalize="on"
      />
      <label for="email" class="form-label">Email Adresse</label>
      <input
        type="email"
        class="form-control"
        id="email"
        name="email"
        placeholder="[email protected]"
        autocomplete="on"
        autocapitalize="on"
      />
      <label for="password" class="form-label">Passwort </label>
      <input
        type="password"
        class="form-control"
        id="password"
        name="password"
        placeholder="min 8 Zeichen mit Zahl und Sonderzeichen"
        autocomplete="off"
        autocapitalize="on"
      />
      <label for="password_confirmation" class="form-label"
        >Passwort Bestätigung
      </label>
      <input
        type="password"
        class="form-control"
        id="password_confirmation"
        name="password_confirmation"
        placeholder="Confirm Password"
        autocomplete="off"
        autocapitalize="on"
      />
      <div class="card-body">
        <a href="#" class="pe-auto">Passwort vergessen</a
        ><a href="#" class="pe-auto">Zum Login</a>
      </div>
      <button type="submit" id="postLogin" class="btn btn-primary">
        Los geht's
      </button>
    </form>

So nothing special. Does anyone have any suggestions? Thank's and have a great day! German comments are also welcome.

0 likes
4 replies
Stephan_P's avatar

Thanks, but no. Don't works. Think I have to check my Babel settings or just try it without compiling js. Can't find any mistakes and when I alert my json body it looks like it should.

{
	"name": "name",
	"email": "[email protected]", ...
}

Thank you anyway for your response.

Stephan_P's avatar

Yes, I tried it without running it with Babel compiler. Now it works. Shit happens... ;-)

siangboon's avatar

419 is related to the session issue, and most commonly is related to the CSRF token ... i think tykus should be the right answer...

Please or to participate in this conversation.