error 403 in production when my `APP_ENV=local` change to production and using FilamentPHP

309 views Asked by At

I have created a droplet in digital Ocean and I test my project in the app_env from local to production, when I do this I end up getting a 403 forbidden error, clearly I can't leave it in local, since I would end up exposing all my .env configuration , now I followed the steps of adding the FilamentUser to the User model and other models where I manage separate users for other panels... I also added public function canAccessPanel, but it keeps returning error 403, do you have any suggestions or ideas about what could be wrong? , or where to check something else?

enter image description here

This is my code in User!


namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;

use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasTenants;
use Filament\Panel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Collection;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable implements HasTenants, FilamentUser
{
    use HasApiTokens, HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    /**
     * 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',
    ];

    //relacion de los usuarios con las empreas
    public function companies(): BelongsToMany
    {
        return $this->belongsToMany(Company::class);
    }

    public function canAccessTenant(Model $tenant): bool
    {
        //
        return $this->companies->contains($tenant);
    }

    public function getTenants(Panel $panel): array|Collection
    {
        //Empresas que va a gestionar o que tiene este usuario 
        return $this->companies;
    }

    public function canAccessPanel(Panel $panel): bool
    {
        return str_ends_with($this->email, '@yourdomain.com') && $this->hasVerifiedEmail();
    }
}```
0

There are 0 answers