0

I have used front side javascript(jquery) and backend Laravel with sanctum. Backend side I have used a virtual host.

-> frontend - localhost/login.html

-> backend - http://alkmy.local/login

env file

APP_ENV=local
APP_KEY=base64:S3rJd8xDyPMOjmuKIR28CFcFcJnMqEwO9A+xFzEZe+Q=
APP_DEBUG=true
APP_DEBUG_bar=true
APP_URL=http://alkmy.local

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=sanctum
DB_USERNAME=root
DB_PASSWORD=vc@123

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=cookie
SESSION_LIFETIME=120

SESSION_DOMAIN=alkmy.local
SANCTUM_STATEFUL_DOMAINS=alkmy.local

Issue enter image description here

If I backend access using 'php artisan serve' and set bellow changes in .env then it works

SESSION_DOMAIN=localhost
SANCTUM_STATEFUL_DOMAINS=localhost

Please Help how I can use laravel sanctum with a virtual host.

Mitul Koradiya
  • 318
  • 2
  • 5
  • 19

2 Answers2

0

its cros problem !

your app must be on same .tld.test

run your frontedapp on example.alkmy.local

github

0

i'm working with laravel sanctum and using vue in front, maybe you have problem with cors, i mean, should be add in cors 'api/*' other problem maybe is that you lost the session... for fix this problem in vue we have a main.js file, like this

store.dispatch('getUser').then(() => {
  new Vue({
    router,
    store,
    render: h => h(App)
  }).$mount('#app')
})

here we use a store.dispatch('getUser')

Trance Code
  • 157
  • 1
  • 10