Jump to content

isLoggedIn() not working


MECU
 Share

Recommended Posts

I'm incorporating PW into a Laravel site layout. For the Login/Logout links, I have:

<?php if ( !wire('user')->isGuest() && wire('user')->id && wire("user")->isLoggedin() ) 
 {
    echo '<li><a href="/pages/control/">Admin</li>
          <li><a href="/pages/control/login/logout/">Logout</li>';
 }
 else
    echo '<li><a href="/pages/control/login/">Login</li>';
?>

I started with just wire('user')->isLoggedin(), and that didn't seem to work, so searching around the forums added in the other items.

Basically, whether I'm logged in or not, I always see a Login link.

If I dd/datadump (a Laravel function) the wire('user') I get what looks like the PW user class. So I've included the PW index.php correctly into my Laravel bootstrap/start.php. 

As an aside, $wire->user->isLoggedIn() doesn't work. It's probably some conflict with Laravel. Switching to use wire('user')->isLoggedIn() let me work, though it gives the wrong result.

EDIT 1:

It works fine on the pages that are pure PW, just not any that are Laravel driven.

Edited by MECU
Link to comment
Share on other sites

It seems I've included ProcessWire correctly, as I can access the API, but the fact that I'm logged is does not register correctly. According to the Include & Bootstrap page, all I need to do is include this in Laravel and I'm done:

require($app['path.base'].'/public/pages/index.php'); 

It seems I need to actually process whether a user is logged in?

Does the fact that I have it installed in a /pages subdirectory matter? I deleted all cookies and tried again and it didn't matter. The cookies don't have a directory 

Link to comment
Share on other sites

Turns out it was a collision between Laravel and PW sessions. Once I removed the Laravel Session provider and alias in /laravel/app/config/app.php it worked great.

I also removed the Auth provider and alias. Not sure if that is also needed to be removed with Session. I didn't test enough to determine that. If the above alone doesn't work, then also remove the Auth and it should work.

Here's everything I commented out to get it to work:

//'Illuminate\Auth\AuthServiceProvider',
//'Illuminate\Session\CommandsServiceProvider',

//'Auth'            => 'Illuminate\Support\Facades\Auth',
//'Session'         => 'Illuminate\Support\Facades\Session',
 
There's also this:
'Illuminate\Session\SessionServiceProvider',
But commenting that out caused Laraval to crash in wanting session help.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...