Deployment
Hi, has anyone here tried deploying their Nuxt frontend on Nuxthub while hosting their Laravel backend on Hostinger? My nameserver is also on Hostinger. I am using Breeze API in my Laravel and have set up a subdomain on Hostinger pointing to my Nuxt frontend URL. However, I always get a CSRF token mismatch error for non-GET requests. I’m not sure what’s wrong. I’ve been searching the internet for a while now but am stuck. Everything works fine when running on localhost.
2 Replies
Hi @Sngt. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided in the knowledge sources, I don't have enough specific details to fully address your particular deployment setup with NuxtHub and Hostinger. However, I can offer some general insights and suggestions related to your CSRF token mismatch issue:
1. CSRF Token Mismatch: This is a common issue when dealing with cross-domain requests between a frontend and backend hosted on different domains or subdomains. The problem you're experiencing is likely related to how cookies and CSRF tokens are being handled across these different domains.
2. Sanctum Configuration: If you're using Laravel Sanctum for authentication, make sure your Sanctum configuration is properly set up to handle requests from your Nuxt frontend domain. In particular, check the
stateful
array in your Sanctum config Stack Overflow Post > Laraval Santcum 419 "CSRF token missmatch" error with nuxt Part 1 (https://stackoverflow.com/questions/78543475).
3. Session and Cookie Configuration: Ensure your Laravel session and cookie configurations are correctly set for cross-domain requests. Pay attention to the domain
and same_site
settings in your session config Stack Overflow Post > Laraval Santcum 419 "CSRF token missmatch" error with nuxt Part 1 (https://stackoverflow.com/questions/78543475).
4. HTTPS: One user reported solving a similar issue by ensuring both the frontend and backend were using HTTPS Stack Overflow Post > Laraval Santcum 419 "CSRF token missmatch" error with nuxt Part 2 (https://stackoverflow.com/questions/78543475). If you're not already doing so, consider using HTTPS for both your Nuxt frontend and Laravel backend.
5. Proxy Configuration: If possible, consider setting up a proxy on your Nuxt application to forward API requests to your Laravel backend. This can help avoid CORS and CSRF issues. You can find more information about proxying in Nuxt in this video: YouTube [Nuxt 3]: The BEST way to proxy your API in Nuxt (https://www.youtube.com/watch?v=J4E5uYz5AY8).
6. Authentication Check: Ensure that your requests are properly authenticated. Sometimes, CSRF token mismatches can occur when the request is not properly authenticated Stack Overflow Post > Laravel PUT/PATCH returns 302 Found and redirects to frontend URL (https://stackoverflow.com/questions/77023324).
If you continue to face issues after trying these suggestions, you may need to provide more specific details about your deployment configuration and the exact error messages you're receiving. You might also want to consider asking for help in the Nuxt community forums or GitHub discussions for more targeted assistance Docs > Community > Getting Help (https://nuxt.com/docs/community/getting-help).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@875262967304835133> Kapa.ai is still learning and improving, please let me know how I did by reacting below.