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
are you using $panel->profile() ?
Code A
Code AOP4w 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
this works on my end
Code A
Code AOP4w 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
ok but this shouldn't lose the session 🤔
toeknee
toeknee4w ago
Have you set the path/url in the panel provider and what does the .env have for the urls?
LeandroFerreira
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 AOP4w 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
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 AOP4w ago
thank you very much it really worked in my case. is this code to save the new password hash into the session?
LeandroFerreira
yep, check the original save method from EditProfile

Did you find this page helpful?