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

ajithlal's avatar

Role based access control using fortify or multiple authentication system using fortify

How to add multiple authentications using fortify?. like, if we have admin, registered user and public user, we have to implement different auth for admin and registered user. Jetstream comes with authentication by default. But how to add a different one using fortify?

0 likes
6 replies
jlrdw's avatar

The same as other versions of laravel.

Also a user is a user, so use authentication for login and use authorization to determine what the "logged" in user can or cannot do with their role.

You can redirect to their area depending on role:

See

https://laracasts.com/discuss/channels/laravel/version-8-redirects

But of course you are free to apply any RBAC you wish. I in some smaller intranet apps use "out of box" authentication but use custom RBAC that works with it. https://gist.github.com/jimgwhit/ed44a6c81815804f1ab910ce9eb88d84

So laravel let's you the developer choose, but has built in if you want to use it.

Jeffrey has many free videos on authorization in his "from scratch" series.

ajithlal's avatar

I think I want to achieve this in another way. I have two users (actually 3. but one is the public user. not part of any authentication) Admin and authenticated user say, author. Author login URL will be website.com/login (provided by jetstream or fortify). Admin login will be website.com/admin/login.

Both users have a different endpoint for login. On earlier versions, we can create these endpoints by copy-pasting the auth provided by laravel. I want to achieve the same using fortify. Is that possible?

jlrdw's avatar

If you scroll down a little in the Authentication chapter you will see:

https://laravel.com/docs/8.x/authentication#authenticating-users

Which states:

You are not required to use the authentication scaffolding included with Laravel Jetstream. If you choose to not use this scaffolding, you will need to manage user authentication using the Laravel authentication classes directly. Don't worry, it's a cinch!

We will access Laravel's authentication services via the Auth facade, so we'll need to make sure to import the Auth facade at the top of the class. Next, let's check out the attempt method:

You may want to re-study this chapter in the new laravel 8, then decide how you want to proceed.

But even with out of the box auth you can still have 2 endpoints. But it would be using same table.

Do you have separate tables. Also have a look at:

https://laracasts.com/discuss/channels/laravel/i-want-to-create-two-types-user-panel-for-two-types-user

ajithlal's avatar

But even with out of the box auth you can still have 2 endpoints. But it would be using same table.

using the same table.

The above-mentioned method will work for me. But I want to know, is it possible to create two endpoints using fortify. or not?

Please or to participate in this conversation.