Using nuxt-auth-sanctum with apps in Docker containers #256
-
Hi,
And my Nuxt app works correctly but now I need to implement registration and authentication (this is an educational e-commerse web app). So now I have two questions:
I tried to dynamically change nuxt.config.ts: export default defineNuxtConfig({
// ...
runtimeConfig: {
apiBaseServer: process.env.NUXT_API_BASE_SERVER, // This is 'http://eshop3-api-nginx'
public: {
apiBaseClient: 'http://api.eshop3.local',
sanctum: {
baseUrl: process.env.NUXT_API_BASE_SERVER, // This is 'http://eshop3-api-nginx'
// ...
}
}
}
// ...
}) default.vue: const config = useRuntimeConfig()
if (import.meta.client) {
// This doesn't work, the module still tries to connect to 'http://eshop3-api-nginx/login' on the client side
config.public.sanctum.baseUrl = config.public.apiBaseClient
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @den15dev! Since cookie authentication for SSR requires to be configured for the same domain, you should keep your CSR and SSR environment as close as possible from the backend URL and config perspective. The easiest solution which I also use for my projects is to set Laravel container name as domain, e.g. You can check an example here - Breeze API Docker container. |
Beta Was this translation helpful? Give feedback.
Hi @den15dev!
Since cookie authentication for SSR requires to be configured for the same domain, you should keep your CSR and SSR environment as close as possible from the backend URL and config perspective. The easiest solution which I also use for my projects is to set Laravel container name as domain, e.g.
laravel.test
which will make it accessible from web browser and Nuxt container, even though it is a domain name.You can check an example here - Breeze API Docker container.