Create a Login Page - Error - 401 (Unauthorized)

Hello I want create a Login Page, but get an error:

Access to fetch at ‘/login’ from origin has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

The Backend is a Laravel-PHP JSON REST API.

I can connect to the backend via terminal:

curl -d ‘{“name”:“c1312asd”, “email":"”,“password”:“12345asdfghj”}’ -H “Content-Type: application/json” http://localhost:8000/login

Get Back the Token.


is there an error ?

const BACKEND_URL = “domain”;

let response = await fetch( BACKEND_URL, { 
  mode: 'cors',
  method: 'POST',
  header: {
    'Accept': "application/json",
    'Content-Type': 'application/json'
  body: JSON.stringify({
    name, password

ok. CORS problem solved.

in cors.php on the backend.

‘paths’ => [’’], // here was a string / url - so it works ‘allowed_methods’ => [’’], ‘allowed_origins’ => [’’], ‘allowed_origins_patterns’ => [], ‘allowed_headers’ => [’’], ‘exposed_headers’ => [’*’], ‘max_age’ => 0, ‘supports_credentials’ => false,

but now: I got token.js:21 POST 401 (Unauthorized)

but with the login data I can login, via CURL and Postman.