Skip to content

Commit

Permalink
Update readme and config file
Browse files Browse the repository at this point in the history
  • Loading branch information
norbybaru committed Mar 7, 2024
1 parent 6845985 commit fd6f899
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

![PASSWORDLESS-AUTH](./loginlink.png)
# LARAVEL PASSWORDLESS AUTHENTICATION
Laravel Passwordless Authentication with Magic Link.
Laravel Passwordless Authentication using Magic Link.

This package allows authentication via email link.
It removes the need for users to provide password to authenticate but rely on user email address to send
them a login link to their inbox to follow to authenticate user securely.
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**

Expand All @@ -22,18 +20,18 @@ php artisan vendor:publish --provider="NorbyBaru\Passwordless\PasswordlessServic
```

## Preparing the database
You need to publish the migration to create table:
Publish the migration to create required table:
```sh
php artisan vendor:publish --provider="NorbyBaru\Passwordless\PasswordlessServiceProvider" --tag="passwordless-migrations"
```
After that, you need to run migrations.
Run migrations.
```sh
php artisan migrate
```

# Basic Usage
## Preparing Model
Open the `User::class` Model and make sure to implements `NorbyBaru\Passwordless\CanUsePasswordlessAuthenticatable::class` and add trait `NorbyBaru\Passwordless\Traits\PasswordlessAuthenticatable::class` to the class
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
<?php
Expand Down Expand Up @@ -71,7 +69,7 @@ eg.
```

## Setup Login Routes
Make sure to setup new login routes and update your application to use the new login route
Update application Login routes to sen Magic Link to user

```php
<?php
Expand Down Expand Up @@ -119,11 +117,20 @@ return [
];
```

## Setup Auth Provider

# 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
Expand Down
10 changes: 0 additions & 10 deletions config/passwordless.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@
*/
'login_route' => 'login',

/*
|--------------------------------------------------------------------------
| Auth Provider
|--------------------------------------------------------------------------
|
|
|
*/
'provider' => 'users',

/*
|--------------------------------------------------------------------------
| Table Name
Expand Down
2 changes: 1 addition & 1 deletion database/migrations/create_passwordless_auth_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
public function up()
{
Schema::create('passwordless_auth', function (Blueprint $table) {
Schema::create(config('passwordless.table'), function (Blueprint $table) {
$table->id();
$table->string('email')->index();
$table->string('token')->unique();
Expand Down
8 changes: 1 addition & 7 deletions src/MagicLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,8 @@ class MagicLink
*/
const MAGIC_LINK_VERIFIED = 'passwordless.verified';

protected TokenInterface $token;

protected UserProvider $user;

public function __construct(TokenInterface $tokenInterface, UserProvider $user)
public function __construct(protected TokenInterface $token, protected UserProvider $user)
{
$this->token = $tokenInterface;
$this->user = $user;
}

public function generateUrl(CanUsePasswordlessAuthenticatable $notifiable, string $token): string
Expand Down

0 comments on commit fd6f899

Please sign in to comment.