auth()->user() is null after login

Simply this....auth()->user() is null after login. Why?
7 Replies
LeandroFerreira
LeandroFerreira4mo ago
where? custom guard?
ocram82
ocram82OP4mo ago
inside public static function getPages(): array function in the others method i can dd it properly any idea on that?
LeandroFerreira
LeandroFerreira4mo ago
what are you trying to do?
ocram82
ocram82OP4mo ago
this:
public static function getPages(): array
{
$pages = [
'index' => Pages\ListWorksites::route('/'),
'edit' => Pages\EditWorksite::route('/{record}/edit'),
];

// this DON'T WORK

if (auth()->user()->hasRole('admin')) {
$pages['create'] = Pages\CreateWorksite::route('/create');
}

return $pages;

}
public static function getPages(): array
{
$pages = [
'index' => Pages\ListWorksites::route('/'),
'edit' => Pages\EditWorksite::route('/{record}/edit'),
];

// this DON'T WORK

if (auth()->user()->hasRole('admin')) {
$pages['create'] = Pages\CreateWorksite::route('/create');
}

return $pages;

}
ocram82
ocram82OP4mo ago
good approach! i'll try this and give a feedback! thanks a lot sorry.....but this doesn't work:
<?php

namespace App\Filament\Shared\Resources\WorksiteResource\Pages;

use App\Filament\Shared\Resources\WorksiteResource;
use Filament\Resources\Pages\CreateRecord;

class CreateWorksite extends CreateRecord
{
protected static string $resource = WorksiteResource::class;

protected static bool $canCreateAnother = false;

protected function getHeaderActions(): array
{
return [

];
}



// THIS DON'T WORK

public static function canAccess(): bool
{
return auth()->user()->isAdmin();
}
}
<?php

namespace App\Filament\Shared\Resources\WorksiteResource\Pages;

use App\Filament\Shared\Resources\WorksiteResource;
use Filament\Resources\Pages\CreateRecord;

class CreateWorksite extends CreateRecord
{
protected static string $resource = WorksiteResource::class;

protected static bool $canCreateAnother = false;

protected function getHeaderActions(): array
{
return [

];
}



// THIS DON'T WORK

public static function canAccess(): bool
{
return auth()->user()->isAdmin();
}
}
Dennis Koch
Dennis Koch4mo ago
You need to provide a bit more info than
// THIS DON'T WORK
Also use Filament::auth() in Filament context
Want results from more Discord servers?
Add your server