F
Filament2mo ago
Jap

Login not working (Production)

I need help fixing my login page, it works on local server with the same setup. I also added session_domain and app_url in env file. When i try to login it keeps redirecting me back to login page.
Solution:
Thanks the problem was in livewire. I forgot to remove/comment this line of code in my service app provider. ``` Livewire::setUpdateRoute(function ($handle) { return Route::post('/custom/livewire/update', $handle); });...
Jump to solution
11 Replies
krekas
krekas2mo ago
check laravel logs. also have you implemented the FilamentUser on the User model with the canAccessPanel method?
Jap
Jap2mo ago
Yes i already did and also im using filament shield
krekas
krekas2mo ago
how does your canAccessPanel looks like?
Jap
Jap2mo ago
public function canAccessPanel(Panel $panel): bool { if ($this->roles->count() == 0) { return false; } return $this->hasVerifiedEmail(); }
krekas
krekas2mo ago
what's the point of checking if there are any roles? double check if you really have any of them
ericmp
ericmp2mo ago
@Jap also
$hasRoles = ! $this->roles()->exists();
$hasRoles = ! $this->roles()->exists();
is better than
$hasRoles = $this->roles->count() == 0;
$hasRoles = $this->roles->count() == 0;
and outputs the same u can test it if u want ^^
\Illuminate\Support\Benchmark::dd([
fn () => $this->roles->count() == 0,
fn () => ! $this->roles()->exists(),
]);
\Illuminate\Support\Benchmark::dd([
fn () => $this->roles->count() == 0,
fn () => ! $this->roles()->exists(),
]);
Jap
Jap2mo ago
thank you ill try this Still not working this is my current source code for my user model.
<?php

namespace App\Models;

use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable implements FilamentUser, MustVerifyEmail
{
use HasFactory, Notifiable, HasRoles;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}

public function canAccessPanel(Panel $panel): bool
{
if (!$this->roles()->exists()) {
return false;
}

return $this->hasVerifiedEmail();
}
}
<?php

namespace App\Models;

use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable implements FilamentUser, MustVerifyEmail
{
use HasFactory, Notifiable, HasRoles;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}

public function canAccessPanel(Panel $panel): bool
{
if (!$this->roles()->exists()) {
return false;
}

return $this->hasVerifiedEmail();
}
}
LeandroFerreira
LeandroFerreira2mo ago
I think it isn't necessary $this->hasVerifiedEmail() if you are using mustVerifyEmail
Jap
Jap2mo ago
I see, i tried only returning true on canAccessPanel same thing happens it just reloads then goes back to login page and no errors in browser console
LeandroFerreira
LeandroFerreira2mo ago
yes, not linked to the issue. I suggest reviewing the server configuration, ensuring Livewire requests are working properly..
Solution
Jap
Jap2mo ago
Thanks the problem was in livewire. I forgot to remove/comment this line of code in my service app provider.
Livewire::setUpdateRoute(function ($handle) {
return Route::post('/custom/livewire/update', $handle);
});

Livewire::setScriptRoute(function ($handle) {
return Route::get('/custom/livewire/livewire.js', $handle);
});
Livewire::setUpdateRoute(function ($handle) {
return Route::post('/custom/livewire/update', $handle);
});

Livewire::setScriptRoute(function ($handle) {
return Route::get('/custom/livewire/livewire.js', $handle);
});
I'm using it to configure livewire's update endpoint if my app is deployed in https://example.com/custom.
Want results from more Discord servers?
Add your server
More Posts