Closed Arametheus closed 3 months ago
@Arametheus First, I need to mention that I shared this code previously on issue #1078 to exemplify how I was using persistent dark mode on my scenario, but that code also requires proper migrations to create a settings table and extensions on the user model to implement the relationship between those tables. I'm not sure if you have managed to figure out all those changes and how you implemented that in your system. In other words, that code won't work as a single copy+paste procedure...
Second, this isn't likely a bug in the package, but more like a custom integration of the feature. So, some questions:
1) How are you sure the SetupDarkModePreference handler is working fine?? Start debugging and tracing your logic so you know when the handle returns (in which step of the logic). Then share that information. Do the same for the other event handler.
2) Is the auth
middleware correctly configured in the group of routes you are accessing? See https://laravel.com/docs/10.x/authentication#protecting-routes
@dfsmania Sorry took me so long to reply got slammed with a few other issues.
So I have a Settings table created and implemented the relationship for the user and that part is working.
When I log or dump the Auth()->user() in SetupDarkModePreference I get my Logged in user. I also added logging to output to DebugBar which is also logging correctly.
I have 3 types of auths (web, locations, partners) set correctly. which is why I created the helper I mentioned since I need to figure out who you are so I correctly use the correct auth's and Classes.
but even with out the helper and logged in as a web(user) if I log or dump out the auth object its null in storeDarkModeSetting
I guess I'm trying to figure out why auth is working fine in SetupDarkModePreference but in storeDarkModeSetting its not and they are 1 line away from each other.
Hi @Arametheus , please backup your StoreDarkModePreference
listener and use the next one instead. I have the next code working on a Laravel 8.x system without any problems. I just want to check what trace do you get when toggling the dark mode button.
<?php
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use JeroenNoten\LaravelAdminLte\Events\DarkModeWasToggled;
class StoreDarkModePreference
{
/**
* The dark mode setting ID used on the database.
*
* @var string
*/
protected $darkModeSettingId = 1;
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param DarkModeWasToggled $event
* @return void
*/
public function handle(DarkModeWasToggled $event)
{
Log::debug('Handling event DarkModeWasToggled ...');
// First, check if user is authenticated.
if (! Auth::check()) {
Log::debug('Can\'t update dark mode setting: user is not auth!');
return;
}
// Get the new dark mode setting for the authenticated user.
$darkModeCfg = $event->darkMode->isEnabled();
$user = Auth::user()->name;
$status = $darkModeCfg ? 'enabled' : 'disabled';
Log::debug("New dark mode setting for user {$user} is: {$status}");
// Store the new dark mode setting for the authenticated user.
//$this->storeDarkModeSetting($darkModeCfg);
//Log::debug("New dark mode setting is now stored on database!");
}
}
Then, share the trace you're getting, and your Laravel version also...
@Arametheus Have you found any solution for your problem, or tested the previous suggestions?
@dfsmania sorry I got slammed again I will get that tested this week and let you know.
Closed, no more feedback, can't reproduce.
So I set-up Persistent Dark mode to save to the DB. the issue I'm having is in the SetupDarkModePreference I get auth just fine but in StoreDarkModePreference Auth is null even though I'm logged in.
I'm running multi-tenacy not that should matter since thats taken care of way before this point.
I added in EventServiceProvider.
my SetupDarkModePreference looks like
my StoreDarkModePreference looks like
and my AuthHelper looks like
its selecting the correct class since I'm signed in as a user.
I don't understand why the read is working fine but the store one is not..
Thanks for any help in advanced.