Welcome Guest, Not a member yet? Register   Sign In
CI4 and Myth Auth
#1

(This post was last modified: 02-11-2020, 04:27 PM by Mobostar.)

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.
Reply
#2

“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?
Reply
#3

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.
Reply
#4

Great! Glad you got it fixed.
Reply
#5

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB