https://github.com/norbybaru/laravel-passwordless-authentication
Laravel Passwordless Authentication with Magic Link
https://github.com/norbybaru/laravel-passwordless-authentication
laravel-authentication laravel-magic-link laravel-passwordless-authentication magic-link-authentication passwordless-authentication
Last synced: 6 months ago
JSON representation
Laravel Passwordless Authentication with Magic Link
- Host: GitHub
- URL: https://github.com/norbybaru/laravel-passwordless-authentication
- Owner: norbybaru
- Created: 2020-04-21T22:57:43.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-08-18T22:20:37.000Z (12 months ago)
- Last Synced: 2025-08-21T11:02:40.678Z (11 months ago)
- Topics: laravel-authentication, laravel-magic-link, laravel-passwordless-authentication, magic-link-authentication, passwordless-authentication
- Language: PHP
- Homepage:
- Size: 78.1 KB
- Stars: 21
- Watchers: 1
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
[](https://github.com/norbybaru/laravel-passwordless-authentication/actions/workflows/run-tests.yml) [](https://github.com/norbybaru/laravel-passwordless-authentication/actions/workflows/phpstan.yml) [](https://github.com/norbybaru/laravel-passwordless-authentication/actions/workflows/pint.yml)

# LARAVEL PASSWORDLESS AUTHENTICATION
Laravel Passwordless Authentication using Magic Link.
This package enables authentication through email links, eliminating the requirement for users to input passwords for authentication. Instead, it leverages the user's email address to send a login link to their inbox. Users can securely authenticate by clicking on this link. It's important to note that the package does not include a user interface for the authentication page; it assumes that the application's login page will be custom-built. Make sure to scaffold your login UI page accordingly to integrate seamlessly with this package.
**PS. Email provider must be setup correctly and working to email magic link to authenticate user**
## Installation
```sh
composer require norbybaru/passwordless-auth
```
## Publishing the config file
```sh
php artisan vendor:publish --provider="NorbyBaru\Passwordless\PasswordlessServiceProvider" --tag="passwordless-config"
```
## Preparing the database
Publish the migration to create required table:
```sh
php artisan vendor:publish --provider="NorbyBaru\Passwordless\PasswordlessServiceProvider" --tag="passwordless-migrations"
```
Run migrations.
```sh
php artisan migrate
```
# Basic Usage
## Preparing Model
Open the `User::class` Model and ensure to implements `NorbyBaru\Passwordless\CanUsePasswordlessAuthenticatable::class` and to add trait `NorbyBaru\Passwordless\Traits\PasswordlessAuthenticatable::class` to the class
```php
'dashboard',
```
- Update `login_route` to the correct route name of your login page to allow redirecting user
back to that page on invalid magic link.
eg.
```
'login_route' => 'auth.login',
```
## Setup Login Routes
Update application Login routes to sen Magic Link to user
```php
validate([
'email' => 'required|email|exists:users',
]);
$status = Passwordless::magicLink()->sendLink($validated);
return redirect()->back()->with([
'status' => trans($message)
]);
});
```
## Setup Mail Provider
Make sure to have your application mail provider setup and working 100% for your Laravel application
```
MAIL_MAILER=
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME="${APP_NAME}"
```
## Setup Translations
Add file `passwordless.php` in your translations directory and copy the entry below.
Feel free to update text to suit your application needs.
```php
return [
'sent' => 'Login link sent to inbox.',
'throttled' => 'Login link was already sent. Please check your inbox or try again later.',
'invalid_token' => 'Invalid link supplied. Please request new one.',
'invalid_user' => 'Invalid user info supplied.',
'verified' => 'Login successful.',
];
```
# Advance Usage
## Override MagicLinkNotification
To override default notification template, override method `sendAuthenticationMagicLink` in your User model which implements interface `CanUsePasswordlessAuthenticatable`
```php
public function sendAuthenticationMagicLink(string $token): void
{
// Replace with your notification class.
// eg. $this->notify(new SendMagicLinkNotification($token));
}
```
## Run Unit Test
```sh
composer test
```
## Run Code Formatter
```sh
composer fmt
```