CodeIgniter Forums
CI4 and Myth Auth - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: CI4 and Myth Auth (/showthread.php?tid=75489)



CI4 and Myth Auth - Mobostar - 02-11-2020

Hello,



I will need an Auth for CI4 and I decided to check out Myth Auth for CI4. So, I installed it via Composer, and did the basic settings following the instructions at https://github.com/lonnieezell/myth-auth.



I have set it to work globally in app/Config/Filters.php:



PHP Code:
public $globals = [
        'before' => [
            'login',
        ],
        'after'  => [
            'toolbar',
        ],
    ]; 


So, when a user browses any page on the website he/she should be redirected to login page if not logged in already.



However, strange things happen when I browse the website. First, the URL ends up with "/index.php/login" despite having URL rewriting enabled and working fine until I started to experiment with Myth Auth. Plus, I get a 404 page.



If I directly type "/login" into the address bar to get rid of the "index.php", I still get a 404.



If I remove "login" from $globals, basically bypassing Myth Auth, things go back to normal and URL rewriting starts to work as expected. I am able to browse website's other pages. But, Myth Auth's login is still a 404.



The login view file of Myth Auth is where it is supposed to be. I could not figure out so far why 1- "index.php" is being inserted into the URL and 2- why the 404 page.



Does anyone using Myth Auth with CI4 have any idea ?



Thanks




SOLVED



I found the reason. Another routing rule in CI4's Routes.php was getting in the way.



/Cheers  Big Grin

FOLLOW UP:

Well, that actually solved only part of the issue. I do not get 404s anymore but the "index.php" is still being inserted into the URI.


RE: CI4 and Myth Auth - MGatner - 02-16-2020

“Login” is a named route so will use your base URL when redirecting. What have you defined as your base URL, in .env or app/Config?


RE: CI4 and Myth Auth - Mobostar - 02-17-2020

Base URL is correct but I had forgotten to change $indexPage = 'index.php' to $indexPage = '' in Config/App.php.
Once I fixed that Auth stopped using "index.php" when redirecting to login page.


RE: CI4 and Myth Auth - MGatner - 02-18-2020

Great! Glad you got it fixed.


RE: CI4 and Myth Auth - InsiteFX - 02-18-2020

Myth/Auth already has a filter for login. Look in the filters folder.

It's just not hooked up as far as I can tell.