Authentication in Laravel doesn’t work some time after the deploy in a specific environment

43 Views Asked by At

I have 2 web platforms built with Laravel that work perfectly fine both on the development environment as well as on local environemnt.

The problem lies in the fact that after I deploy these applications on a cloud infrastructure as a service provider, the applications work for approximatelly ~ 1 / 2 hours, sometimes even less, and then, on every login request it redirects me to back to the login page, even though the credentials on the login attempt are correct.

In between the login request and the redirect response I get blank view with the XSRF token stored in the session, but only for a few miliseconds.

For a clearer view of the problem I need to give you the full context so I will briefly document the infrastructure and the architecture on which the application runs

The applications use the following technologies:

  • Laravel (web platform built in the old fashioned monolith style) v10
  • MariaDB v10.7.5
  • Redis cache database v.6.2.7
  • Melisearch v0.27.2

For each one of these technologies there is a Docker container. The communication between them is facilitated by a traefik Docker network. The applications works as in the following diagram:

application arhitecture

These are some of the environment configuration variables I use that I think might be relevant for the problem:

  • for one of the platforms are these:
CACHE_DRIVER: "redis"
QUEUE_CONNECTION: "redis"
SESSION_DRIVER: "redis"
  • for the other platfom are just the default ones:
also for the second web platform I did’t configure the Redis and Melisearch services and I only run 2 Docker containers, for the app and database.
CACHE_DRIVER: "file"
QUEUE_CONNECTION: "sync"
SESSION_DRIVER: "file"

The following things can be done to temporarily get the app working:

  • ssh-ing into the VPS and manually restarting the container
  • clearing the following cookies form the browser’s storage

cookie one

cookie nr. 2

Note that the develop environment, the one on which the web applications work with no problems is on a self-hosted and maintained server that also has a DNS, CDN and revers-proxy provider on top

Has someone else encountered this wierd behaviour? If so what’s causing it and how could it be solved?

1

There are 1 best solutions below

4
mobieljoy On

The fact that it takes a different amount of time every deploy makes me think the configuration might be cached and that just runs out after x amount of hours. In any case I would definitely check any chache related commands, like php artisan optimize for example.

Also, have you configured the CORS middlewares? I've run into similar issues while deploying.