Skip to content

Auth Module

The Auth module handles authentication and user management. It is a core module, meaning it is always loaded and cannot be disabled.

Overview

  • User login / logout
  • User CRUD (create, edit, delete, list)
  • Artisan command to create users from CLI
  • Dispatches events when users are created or edited (consumed by other modules like Permissions)

Routes

Web

MethodURINameMiddleware
GET/admin/loginloginguest
POST/admin/loginadmin.login.requestguest, throttle:5,1
POST/admin/logoutadmin.logoutauth
GET/admin/users/listadmin.users.indexauth
GET/admin/users/createadmin.users.createauth, can:user_create
POST/admin/users/createadmin.users.create.requestauth, can:user_create
GET/admin/users/edit/{user}admin.users.editauth, can:user_edit
PUT/admin/users/editadmin.users.edit.requestauth, can:user_edit
DELETE/admin/users/delete/{user}admin.users.deleteauth, can:user_delete

API

MethodURINameMiddleware
GET/api/usersapi.users.listauth

Used internally by the AssignRole component to populate the user list when assigning users to a role.

Permissions

KeyDisplay NameDescription
user_createCreate new userAbility to create a new user
user_editEdit userAbility to edit an existing user
user_deleteDelete userAbility to delete a user
user_viewView userAbility to view user list

Checking permissions

PHP:

php
Gate::allows('user_create');

// Via middleware on routes
Route::get('/users/create', ...)->middleware('can:user_create');

Vue:

ts
import {useGate} from '@modules/Module/Composables/useGate';

const gate = useGate();

if (gate.can('user_create')) {
    // show create button
}

Events

UserCreated

Dispatched after a user is successfully created via the web form.

php
use App\Core\Auth\Events\UserCreated;

public User $user;
public array $payload; // validated form data including 'extensions'

Example listener:

php
\Event::listen(UserCreated::class, function (UserCreated $event) {
    // $event->user    — the newly created User model
    // $event->payload — the full validated request data
});

UserEdited

Dispatched after a user is successfully updated via the web form.

php
use App\Core\Auth\Events\UserEdited;

public User $user;
public array $payload;

TIP

These events are the main integration point for the Permissions module, which listens to them to sync roles and direct permissions after user creation or edition.

Extension Points

Point nameLocationProps passed
users.create.startTop of the create user formv-model (extensions)
users.create.endBottom of the create user formv-model (extensions)
users.edit.startTop of the edit user formv-model, user
users.edit.endBottom of the edit user formv-model, user

Registering a component on an extension point:

ts
// app/Modules/YourModule/Resources/js/extensions.ts
import ExtensionRegistry from '@modules/Module/ExtensionRegistry';
import MyComponent from './Components/MyComponent.vue';

ExtensionRegistry.register('users.create.end', MyComponent);

Your component receives the extensions object as a v-model and any additional props defined in extension-props.

vue

<script lang="ts" setup>
    const extensionValues = defineModel<Record<string, unknown>>({required: true});

    // Add your own key to the shared extensions payload
    extensionValues.value.myData = {foo: 'bar'};
</script>

On the Laravel side, the extensions key is passed through CreateUserRequest / EditUserRequest as:

php
'extensions' => 'sometimes|array'

It is then forwarded to the dispatched event (UserCreated, UserEdited), where other modules can read it.

Artisan Command

bash
# You will be prompted for a password
php artisan auth:create-user "John Doe" john@example.com

# Or pass the password directly (not recommended in production)
php artisan auth:create-user "John Doe" john@example.com --password=secret123
Users
├── Create user  →  admin.users.create
└── List users   →  admin.users.index