mimachh/2fa

There is no license information available for the latest version (1.0.4) of this package.

Two Factor Authentication for Laravel Inertia Breeze

Installs: 19

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Language:TypeScript

1.0.4 2024-11-23 21:08 UTC

This package is auto-updated.

Last update: 2024-11-23 21:09:11 UTC


README

composer require mimachh/2fa

Add the trait to the user model

use Mimachh\TwoFactor\HasTwoFactor;

use HasTwoFactor;

Publish the migrations and migrate.

php artisan vendor:publish --tag=2fa-migrations

php artisan migrate

Validation

To validate the code you need to add in the LoginRequest of Breeze (if you use Breeze) :

'code_2fa' => ['nullable', 'string', 'size:6'],

Routing

Replace your breeze (in auth.php) or custom route login by

Route::post('/login', [TwoFactorController::class, 'store'])->name('login.2fa');

UI

You can use the inertia/react login (and register, confirmation mail etc) from the package, publishing them. You need : ShadcnUI + Inertia + React + Zustand

php artisan vendor:publish --tag=2fa-assets

Then install shadcn component + zustand library and use it in your own page and component.

npx shadcn@latest add button input label input-otp
npm i zustand
import LoginForm from '@/Components/mimachh/2fa/login/LoginForm';

 <LoginForm />

Mail

You need to send email with the 2fa code.

First publish the mail view :

php artisan vendor:publish --tag=2fa-mail

Now email will work.