❓ Support
P Pete Swan Aug 29, 2024

Help needed with integration and roles

Hi guys,

I’ve installed as a package. Currently using Jetstream/Spatie/Livewire

I’ve found how to block route from guests.

I already have user roles setup.

I would like any users with a certain role to automatically have user accounts in the forum and access to it (not all logged in users, only ones with a certain role).

How do I do this?

⁨1⁩ ⁨Comment⁩

Toby Toby Waterhole Founder Sep 1, 2024

Hi @Pete Swan, thanks for your question.

Take a look at the Laravel Authentication Integration docs. When implementing the HasWaterholeUser trait on your application's User model, you will want to override the toWaterholeUser() method so that it only returns a PendingUser object if the user has the correct role that allows them to access the forum:

    public function toWaterholeUser(): ?PendingUser
    {
        if (!$this->roles->contains(ROLE_ID)) {
            return null;
        }

        return new PendingUser(
            identifier: $this->getAuthIdentifier(),
            email: $this->email,
            name: $this->name,
        );
    }