From baf036af5d92bd8bd6d575b61a863f1c12bb9b33 Mon Sep 17 00:00:00 2001 From: Norby Baruani Date: Thu, 7 Mar 2024 15:17:47 +0200 Subject: [PATCH] Update readme and config file (#18) * Update readme and config file * refactor --- .github/workflows/phpstan.yml | 4 --- .github/workflows/pint.yml | 3 --- README.md | 27 ++++++++++++------- config/passwordless.php | 10 ------- .../create_passwordless_auth_table.php | 2 +- src/MagicLink.php | 8 +----- 6 files changed, 19 insertions(+), 35 deletions(-) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index a4dcb09..20819f1 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -5,10 +5,6 @@ on: paths: - '**.php' - 'phpstan.neon.dist' - pull_request: - paths: - - '**.php' - - 'phpstan.neon.dist' jobs: diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index 93828fb..15cdb54 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -4,9 +4,6 @@ on: push: paths: - '**.php' - pull_request: - paths: - - '**.php' jobs: pint: diff --git a/README.md b/README.md index 3805e39..5abd3db 100644 --- a/README.md +++ b/README.md @@ -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** @@ -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 notify(new SendMagicLinkNotification($token)); +} +``` + ## Run Unit Test ```sh composer test diff --git a/config/passwordless.php b/config/passwordless.php index 98f53e0..7628519 100644 --- a/config/passwordless.php +++ b/config/passwordless.php @@ -35,16 +35,6 @@ */ 'login_route' => 'login', - /* - |-------------------------------------------------------------------------- - | Auth Provider - |-------------------------------------------------------------------------- - | - | - | - */ - 'provider' => 'users', - /* |-------------------------------------------------------------------------- | Table Name diff --git a/database/migrations/create_passwordless_auth_table.php b/database/migrations/create_passwordless_auth_table.php index e8f04b5..337d004 100644 --- a/database/migrations/create_passwordless_auth_table.php +++ b/database/migrations/create_passwordless_auth_table.php @@ -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(); diff --git a/src/MagicLink.php b/src/MagicLink.php index d481d08..b60aee7 100644 --- a/src/MagicLink.php +++ b/src/MagicLink.php @@ -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