Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MezoZK's avatar
Level 1

How to know which role the user signed in with?

I'm working with Laravel Sanctum API, each user can have multiple roles (for example: role1, role2 and role3) and I have a separate login form for each role. What's the best way to store the role of the current user and retrieve it when I want to?

0 likes
2 replies
jlrdw's avatar

Do it the other way:

If the method requires say role2, check if that's one of the logged in users roles.

If so they CAN do it.

However with an API you should be looking at token abilities. Also you refer to roles, would a regular web app be better suited for you needs here?

1 like
MezoZK's avatar
Level 1

@jlrdw It's a role based mobile app. I think I'll go with token abilities. Thank you very much.

1 like

Please or to participate in this conversation.