Scroll down and see:
To format code or text into its own distinct block, use triple backticks.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm facing an issue with sharing Laravel Sanctum sessions across subdomains in a Nuxt.js app. Here's the breakdown of my setup:
Laravel Configuration (.env file): Session Configuration:
dotenv Copy code SESSION_DRIVER=database SESSION_DOMAIN=.example.com SESSION_SAME_SITE=none Sanctum Configuration:
dotenv Copy code SANCTUM_STATEFUL_DOMAINS=example.com,dashboard.example.com,marketplace.example.com Nuxt Configuration (.env or .env.development/.env.production): Axios Configuration:
dotenv Copy code API_ENDPOINT=https://api.example.com Nuxt Auth Configuration:
dotenv Copy code APP_URL=https://example.com APP_URL_DASHBOARD=https://dashboard.example.com Nuxt Auth Strategy: I'm using the Laravel Sanctum strategy in Nuxt:
javascript
Copy code
auth: {
strategies: {
'laravelSanctum': {
provider: 'laravel/sanctum',
url: process.env.API_ENDPOINT,
endpoints: {
login: { url: '/api/auth/login', method: 'post', propertyName: 'token' },
logout: { url: '/api/auth/logout', method: 'post' },
user: { url:'/api/user', method: 'get', propertyName: false }
}
},
// Other strategies...
},
redirect: {
login: ${process.env.APP_URL}/auth/login,
logout: ${process.env.APP_URL}/auth/login,
callback: ${process.env.APP_URL}/auth/login,
home: process.env.APP_URL_DASHBOARD ?? '/'
}
}
Problem:
When a user logs in from the root domain (example.com), I can retrieve the authenticated user using this.$auth.user(). However, when navigating to subdomains like dashboard.example.com, the authenticated user is not being recognized (this.$auth.user() returns null).
Expected Behavior: I want the user session to be shared across all subdomains after logging in from the root domain.
Additional Information: Laravel version: 8.x Nuxt.js version: 2.x Laravel Sanctum middleware (EnsureFrontendRequestsAreStateful) is configured appropriately. I appreciate any insights or guidance on resolving this session sharing issue. Thank you!
Please or to participate in this conversation.