Prevent Logout when changing Admin Password

I created a Page called Change Password, and the form is just this:

<?php

namespace App\Filament\Pages;

use Auth;
use Filament\Pages\Page;
use Filament\Facades\Filament;
use Illuminate\Support\HtmlString;
use Filament\Forms\Components\Grid;
use Filament\Forms\Contracts\HasForms;
use Filament\Notifications\Notification;
use Filament\Forms\Components\Placeholder;
use Phpsa\FilamentPasswordReveal\Password;
use App\Notifications\Admin\PasswordUpdated;
use Illuminate\Validation\ValidationException;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Http\Responses\Auth\Contracts\LoginResponse;

class ChangePassword extends Page implements HasForms
{
    use InteractsWithForms;

    protected static ?string $navigationGroup = 'Settings';

    protected static ?string $navigationIcon = 'heroicon-o-key';

    protected static string $view = 'filament.pages.change-password';

    public $password, $password_confirmation;

    protected function getFormSchema() : array
    {
        return [
            Password::make('password')
                ->label('New Password')
                ->revealable()
                ->minLength(8)
                ->maxLength(16)
                ->required()
                ->confirmed(),
            Password::make('password_confirmation')
                ->label('Confirm Password')
                ->revealable()      
                ->required()
        ];
    }

    public function update()
    {
        $data = $this->form->getState();

        $user = Auth::user();
        $user->password = $data['password'];
        $user->save();

        $user->notify(new PasswordUpdated);

        return redirect('admin');
    }
}


Also, Everytime I hit submit form, it redirects to /login and not /admin/login.
Was this page helpful?