jhull
1 month ago
586
4
Laravel

Redirect on SPA after Laravel Airlock Login

Posted 1 month ago by jhull

ALMOST got this all figured out...

SPA is on spa.app.localhost:8888 Laravel API is on api.app.localhost

While in the SPA I call a successful login:

      async login() {
          console.log('login attempt')
          await this.$axios.get('/airlock/csrf-cookie');
          await this.$axios.post('/login', { email: this.account.email, password: this.account.password }).then(resp => {
            console.log('success login')
            this.$router.push({name: 'dashboard'})
          })
      },

I get the CSRF token. And I get the successful Login (subseq. URLs in the SPA work great...)

BUT, for some reason, Laravel is trying to redirect me and I get this error:

Access to XMLHttpRequest at 'https://api.app.localhost/home' (redirected from 'https://api.app.localhost/login') from origin 'http://spa.app.localhost:8888' 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.

In my CORS I have :

'allowed_origins' => [
    'http://spa.app.localhost',
    'https://api.app.localhost'
]

Any idea what is going on here?

Please sign in or create an account to participate in this conversation.