auth() differs from my localapi and remote |
Hello.
I am not very knowable on CodeIgniter or shield, but I was able to get my project going locally on my machine. I created a API made in codeigniter4 and shield. It works nice locally. Two days ago I place it on a server and I am running the frontend from my local machine. The online API behaves differently from my local API and believe me that I tested all that I could, so I request for help. On the server I tried to debug and to provide information for this post. On my Controllers/AuthController.php inside the userlogin() function, I made sure that the login is working using: PHP Code: this outputs for the log file: INFO - 2024-05-04 10:51:58 --> auth()->loggedIn(): 1 That looks ok, login information is also fetched (name, id, ...). All ok and equal to my localhost. After the login, and after the user presses a button to go to a reserved area, a filter is applied and here the code: PHP Code: <?php outputs: INFO - 2024-05-04 10:51:58 --> Is user logged: (note that it does not contain 0 or 1, it is simply empty). $user is also null. On my localserver this contains the correct information. No other error is detected. It is like auth() is not working. I checked and the auth service is loaded on the Autoload.php, though a helper. Thank you for any advice.
Solution was to:
public string $samesite = 'None'; on the Config\Cookie.php Might help others
No it won't, That is the Web CORS.
Cross-Origin Resource Sharing (CORS) What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Good morning.
In my case, both the CORS and the cookies settings had to be changed to suit my setup. For the CORS I had to set the allow-origin header to allow the different origins rather than the same domain. This fixed the browser errors. Since my authentication was cookie based - using shield - the cookies settings needed also to be set as on my previous post. This fixed the error that I described on the first post. |
Welcome Guest, Not a member yet? Register Sign In |