Search code examples
laravelauthenticationroleslaravel-sanctum

Sanctum authentication with roles


I'm trying to implement Sanctum SPA authentication with roles (user/admin). The thing is that I want to use separate admin table. Read all of the laravel documentation related to that subject but with no result. Tried to make a new guard and provider inside of config/auth.php but didn't succeed at conjunction it with Sanctum. Any additional resources and ides how to do it will be appreciated! :)


Solution

  • Sanctum (SPA auth) only deals with authentication (who you are) - what you are asking/looking for is how to authorize users (what you can do) to perform/access specific resources.

    If what you need is only to separate users between regular users and admins, you can get away with a boolean column on the users table: is_admin and then use that to check wether a user is an admin or not.

    If you need more granular control, you could probably make use of Spatie's laravel-permissions package.