Skip to content

mtvbrianking/multi-auth

Repository files navigation

Laravel Multi-Authentication Package

Total Downloads Latest Stable Version Quality Coverage Unit Tests

This package gives you the ability to separate user areas in your application.

E.g, an ecommerce application with customers, sellers, and administrators user areas using auth guards

Prerequisite

This package only extends the official laravel/breeze starter kit, it doesn't regenerate the frontend assets [js, css - tailwind, vite, ...]

Therefore, you need to use it after scaffolding basic auth using Breeze.

Breaking Changes

For old versions (Laravel v9 and below) refer to v11

Installation

composer require bmatovu/multi-auth --dev

Scaffolding

php artisan multi-auth:install admin

Register service provider

config/app.php

  'providers' => [
      /*
      * Package Service Providers...
      */
+     App\Modules\Admins\AdminServiceProvider::class,
  ],

Register JS entry point in Vite (Inertia - Vue, React)

vite.config.js

  export default defineConfig({
      plugins: [
          laravel({
-             input: 'resources/js/app.js',
+             input: [
+                 'resources/js/app.js',
+                 'resources/js/Admins/app.js',
+             ],
-             ssr: 'resources/js/ssr.js',
+             ssr: [
+                 'resources/js/ssr.js',
+                 'resources/js/Admins/ssr.js',
+             ],
              refresh: true,
          }),
          ...
      ],
  });

Read more about Inertia Server Side Rendering

Recompile frontend assets

npm run build

Run Database Migrations

php artisan migrate

Possible approaches for separating user areas

Using sub-domains

Separate user areas by sub-domains.

I would use separate repos for each sub-domain

URI User Group
larastore.com customers
seller.larastore.com sellers
admin.larastore.com administrators

Using URLs*

Separate user areas based on URLs. Restricted with auth guards

* What this package offers

URI User Group
larastore.com customers
larastore.com/seller sellers
larastore.com/admin administrators

Using roles

Restrict access based on the user's roles and permissions

I'd stay away from this approach as it'd more complex to maintain for large projects

URI User Group
larastore.com customers, sellers, administrators