F
Filament2mo ago
Code A

Route [login] not defined Error After Password Update in Filament

After implementing a profile edit feature in Filament, I'm encountering an issue where updating the password leads to session loss and a "Route [login] not defined" error. does anyone have the same problem?
Solution:
try ```php $user->update($data); if ($user->wasChanged('password')) {...
Jump to solution
11 Replies
LeandroFerreira
LeandroFerreira2mo ago
are you using $panel->profile() ?
Code A
Code AOP2mo ago
yes I used $panel->profile and I added userMenuItems like this
->profile()
->userMenuItems([
'profile' => MenuItem::make()->url(fn (): string => EditProfile::getUrl())
])
->profile()
->userMenuItems([
'profile' => MenuItem::make()->url(fn (): string => EditProfile::getUrl())
])
because I have some fields that I have to edit also in the profile edit
LeandroFerreira
LeandroFerreira2mo ago
this works on my end
Code A
Code AOP2mo ago
for the current solution I added a web.php like this
Route::get('/login', function () { return redirect('/admin/login'); })->name('login');
Route::get('/login', function () { return redirect('/admin/login'); })->name('login');
but the drawback is that the user has to re-login
LeandroFerreira
LeandroFerreira2mo ago
ok but this shouldn't lose the session 🤔
toeknee
toeknee2mo ago
Have you set the path/url in the panel provider and what does the .env have for the urls?
LeandroFerreira
LeandroFerreira2mo ago
Did you override the save method? This should keep the session
if (request()->hasSession() && array_key_exists('password', $data)) {
request()->session()->put([
'password_hash_' . Filament::getAuthGuard() => $data['password'],
]);
}
if (request()->hasSession() && array_key_exists('password', $data)) {
request()->session()->put([
'password_hash_' . Filament::getAuthGuard() => $data['password'],
]);
}
Code A
Code AOP2mo ago
Here I don't use the save method, I use the submit method because here I use a custom page.
class EditProfile extends Page
{
...
public function submit()
{
$user = Auth::user();
$data = [
...
];
if ($this->password) {
$data['password'] = Hash::make($this->password);
}


$user->update($data);
return redirect()->to('/admin');
}
}
class EditProfile extends Page
{
...
public function submit()
{
$user = Auth::user();
$data = [
...
];
if ($this->password) {
$data['password'] = Hash::make($this->password);
}


$user->update($data);
return redirect()->to('/admin');
}
}
Solution
LeandroFerreira
LeandroFerreira2mo ago
try
$user->update($data);

if ($user->wasChanged('password')) {
session()->put('password_hash_'.Filament::getAuthGuard(), $user->password);
}
$user->update($data);

if ($user->wasChanged('password')) {
session()->put('password_hash_'.Filament::getAuthGuard(), $user->password);
}
Code A
Code AOP2mo ago
thank you very much it really worked in my case. is this code to save the new password hash into the session?
LeandroFerreira
LeandroFerreira2mo ago
yep, check the original save method from EditProfile

Did you find this page helpful?