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

pirmax's avatar

Issue with CORS and Laravel 10 on subdomain

Hi,

I use Laravel 10 with Breeze to use boilerplate of Inertia and React.

My problem is I use subdomain :

  • one for auth.laravel.test
  • second for dashboard.laravel.test

Auth log the user when he click on submit button. The redirection is not handled and I get this error on console :

Access to XMLHttpRequest at 'http://dashboard.laravel.test/' (redirected from 'http://auth.laravel.test/login') from origin 'http://auth.laravel.test' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I want my user is redirect to dashboard.laravel.test when he click on submit button from React.

My login controller :

public function store(LoginRequest $request): RedirectResponse
    {
        $request->authenticate();

        $request->session()->regenerate();

        return redirect()->intended(route('dashboard.home'));
    }

My cors.php config file :

<?php

return [

    'paths' => ['api/*', 'sanctum/csrf-cookie'],

    'allowed_methods' => ['*'],

    'allowed_origins' => ['*'],

    'allowed_origins_patterns' => [],

    'allowed_headers' => ['*'],

    'exposed_headers' => [],

    'max_age' => 0,

    'supports_credentials' => false,

];

My React component for login :

const submit = (e) => {
        e.preventDefault();

        post(route('login'));
    };

Thanks for help.

0 likes
0 replies

Please or to participate in this conversation.