AdminAuth::login() registers four routes:

Finding the user

The user is found by the first of these parameters:
  • identifier, compared with every login column of the model, i.e. email and phone
  • email
  • phone, formatted to E.164
Add another login column by overriding getRequestCasts() in your controller:
app/Http/Controllers/Auth/LoginController.php
Override findUser() when users are stored in several models, or when some of them must not sign in:
app/Http/Controllers/Auth/LoginController.php

Password login

POST /api/auth/login
Wrong credentials answer 401.

OTP login

  1. POST auth/login/otp sends a code to the e-mail or phone of the user. verificator selects the channel, email or phone. It defaults to AUTH_VERIFICATOR.
  2. POST auth/login/otp-verify with token signs the user in, and marks the e-mail or phone as verified.
The code is valid for 15 minutes. Enable and configure OTP codes first, see OTP codes.

Social login

POST auth/login/socialite/{driver} signs in with an access token or ID token from a mobile or web SDK of the provider. The user is found or registered by the crudadmin/socialite package, and its e-mail is marked as verified.
POST /api/auth/login/socialite/google

Login response

  • driver is the table of the user model.
  • user is the result of setAuthResponse() of the model.
  • device_tokens lists the push notification tokens of the user when notifications are enabled.
  • token is a new Sanctum token. Send it as Authorization: Bearer {token}.

Bootstrap response

With admin_helpers.auth.response = 'bootstrap', login, registration and password reset return the authenticated() sections of the bootstrap request selected by the app-type header, plus the auth section with the new token. Projects get the data of the signed in user in one response, e.g. the merged cart of an e-shop.
The sections are in store when autoajax.store is enabled, otherwise merged into data. The bootstrap class must extend AdminHelpers\Utilities\BootstrapRequest.

Login controller

Extend the default controller to change the guard or the response.
app/Http/Controllers/Auth/LoginController.php

Custom response

Override authorizedResponse(). Share it with the registration controller through a trait, so both return the same data. This example returns the bootstrap request of the signed in user:
app/Utilities/Traits/HasAuthResponse.php
$type is the name of the new token: login, register or social. It is null for the user route, which creates no token.

Token abilities

Tokens have the * ability by default. Override tokenAbilities() to limit them:
app/Http/Controllers/Auth/LoginController.php

Signed in user

GET user returns the same response as the login, without a new token. Register it in a group with your auth middleware.

Logout

auth/logout deletes the current token, and the push notification tokens of the device which used it.