Email Verification
Hello everyone, I've set up emailVerification() in my AdminPanelProvider. How can I send a verification request email upon creating a new user using the UserResource?
Thanks a lot, everyone!
5 Replies
Thank you very much, Leandro Ferreira. I receive the email correctly, but when I click the link, I get a 403 error: THIS ACTION IS UNAUTHORIZED.
What am I doing wrong?
Did you add the MustVerifyEmail?
Are you using multiple panels?
This is 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 Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable implements FilamentUser, MustVerifyEmail
{
use HasApiTokens, HasFactory, Notifiable, HasRoles;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
'customer_id',
'professor_id',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
public function canAccessPanel(Panel $panel): bool
{
return str_ends_with($this->email, '@evolvestudio.it') && $this->hasVerifiedEmail();
}
public function activity()
{
return $this->hasMany(ActivityType::class);
}
public function customer()
{
return $this->belongsTo(Customer::class);
}
public function professor()
{
return $this->belongsTo(Professor::class);
}
}
i don't using multiple panels
This is the AdminPanelProvider
return $panel
->default()
->id('admin')
->path('')
->login()
->passwordReset()
->emailVerification()
->profile()
->colors([
'primary' => '#14315b'
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->pages([
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->maxContentWidth(MaxWidth::Full)
->authMiddleware([
Authenticate::class,
])
->plugin(
FilamentSpatieLaravelHealthPlugin::make()
->usingPage(HealthCheckResults::class)
);
Leandro, can you help me please?Hello, the issue seems to be related to authentication. To access the link, users must be logged in. If you've created a new account with the email '[email protected]' in the user resource, you need to authenticate this account first and then proceed to access the link for email verification.