Reputation: 83
I have an issue that I've been troubleshooting for days that just doesn't make any sense to me. I'm hoping someone has any idea to help!
I'm working on a page where you need to be logged in. The first login works, and I am redirected to the landing page. I see the session variables in my console.
If I refresh the page or try to submit the form on that page I am redirected to the login page and am logged out.
Here is the strange part-
-If I use our production database, instead of the development database, the code works fine and stays logged in (so then I think the issue is the database).
-However, if I use my login from the development database in my colleagues developer space (with the same checked out code), there are no problems. (then I think the issue is with the browser).
-If I use a different browser, totally different machine, clear cookies...I still have the problem.
We are using Codeigniter 4, with CodeIgniter-Ion-Auth for authentication. This is the code on the controller page checking the login:
$this->ionAuth = new \IonAuth\Libraries\IonAuth();
//a user must be logged in to go here so check if they are logged in and are an admin
if (!$this->ionAuth->loggedIn()) {
$this->session->setTempdata('message', 'Please log in to access this part of the website');
// for CI4/CI3 redirection use just uri_string
$this->session->setTempdata('destination', uri_string(current_url()));
// for CI4 use url
$this->session->setTempdata('url', current_url());
return redirect()->to('auth/login');
exit;
}
I tried:
-Creating a new user in the development database and using that user to log in (still have the issue)
-using my colleagues login credentials from the development database in my development space on my machine (still have the issue)
-Clearing cookies, using incognito mode, using different machine (still have the issue)
-Flushing DNS/reboot router and computer (still have the issue)
Any ideas are appreciated!
Upvotes: 0
Views: 49
Reputation: 83
I was able to fix the issue but still don't quite understand the why. We have Codeigniter 3 and Codeigniter 4 running side by side while we do a large migration project. I had my index.php for CI3 set to the production database. When my .env for CI4 was set to development, things didn't work. When I changed the index.php to development, and the two matched, I was able to stay logged in.
The code for CI4 pages shouldn't be hitting CI3 code, so I'm going to try to track down why that was happening. It's a complex configuration we have going on, but we have an extremely large code base that needs to be rewritten.
Upvotes: 0