F
Filament14mo ago
harps

Changing password error "Email already exists"

I seem to be getting this "The email address has already been taken" when changing my passwords. I have changed my user model to allow duplicate email addresses and use another uniques field 'name' for login. Not ideal but the way the client currently works we need to do it in the short term. Everything works and I can create accounts with the same email address and users login with unique name fine. The issue is that on the profile page the email field is checking for uniqueness, what os the best way to override that?
Solution:
just change the getEmailFormComponent() method: ```php protected function getEmailFormComponent(): Component { return TextInput::make('email')...
Jump to solution
9 Replies
harps
harpsOP14mo ago
Thanks @awcodes, I couldn't see how to remove uniqueness from the email field on the profile edit page. I think I need to create a custom edit profile page with a form in that. I'm just looking into that now. https://filamentphp.com/docs/3.x/panels/users#customizing-the-authentication-features
awcodes
awcodes14mo ago
this is what you are looking for. it applies to any record field that needs to be unique. Field::make('email')->unique(ignoreRecord: true)
awcodes
awcodes14mo ago
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
harps
harpsOP14mo ago
I don't want email to be unique, I want to remove the uniqueness. I have done this on all the user resouerce pages apart from the profile page.
awcodes
awcodes14mo ago
sorry, misunderstood, you should just be able to extend the Profile Page and set your own email field there. then in the panel tell the profile method to use your class instead of Filament's default one.
harps
harpsOP14mo ago
I have got so far with extending the user profile page but I get a livewire error. Unable to find component: [app.filament.auth.pages.edit-profile] My code looks like this (Basically the basic page for testing)
<?php

namespace App\Filament\Auth\Pages;

use Filament\Forms\Form;
use Filament\Pages\Auth\EditProfile as BaseEditProfile;

class EditProfile extends BaseEditProfile
{

public function form(Form $form): Form
{
return $form
->schema([
$this->getNameFormComponent(),
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
]);
}
}
<?php

namespace App\Filament\Auth\Pages;

use Filament\Forms\Form;
use Filament\Pages\Auth\EditProfile as BaseEditProfile;

class EditProfile extends BaseEditProfile
{

public function form(Form $form): Form
{
return $form
->schema([
$this->getNameFormComponent(),
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getPasswordConfirmationFormComponent(),
]);
}
}
The form loads but if you click save I get the error
Solution
awcodes
awcodes14mo ago
just change the getEmailFormComponent() method:
protected function getEmailFormComponent(): Component
{
return TextInput::make('email')
->label(__('filament-panels::pages/auth/edit-profile.form.email.label'))
->email()
->required()
->maxLength(255);
// drop this line ->unique(ignoreRecord: true);
}
protected function getEmailFormComponent(): Component
{
return TextInput::make('email')
->label(__('filament-panels::pages/auth/edit-profile.form.email.label'))
->email()
->required()
->maxLength(255);
// drop this line ->unique(ignoreRecord: true);
}
awcodes
awcodes14mo ago
leave everything else the same this is actually the only method you would need in your custom class every thing else can stay in the base class
Want results from more Discord servers?
Add your server