Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Login Link Laravel Package

moox/login-link

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require moox/login-link
    php artisan mooxlogin-link:install
    

    This runs migrations and publishes config/views by default.

  2. First Use Case:

    • Add the login link to your Blade template:
      <x-login-link />
      
    • Or generate a one-time login link via Tinker:
      $link = \Moox\LoginLink\LoginLink::create();
      echo $link->url; // Outputs a signed, time-limited login URL
      
  3. Where to Look First:

    • Config: config/login-link.php (adjust token lifetime, URL patterns, etc.).
    • Migrations: database/migrations/[timestamp]_create_login_link_tokens_table.php (customize token storage).
    • Blade Component: resources/views/vendor/login-link/link.blade.php (override styling/behavior).

Implementation Patterns

Core Workflows

  1. Generating Links:

    • Programmatic:
      $link = \Moox\LoginLink\LoginLink::create([
          'expires_in' => now()->addMinutes(15),
          'redirect_to' => route('dashboard'),
      ]);
      
    • Via API/Controller:
      use Moox\LoginLink\Facades\LoginLink;
      
      public function generateLoginLink(Request $request) {
          return response()->json(['url' => LoginLink::create()->url]);
      }
      
  2. Handling Incoming Links:

    • Middleware: Use Moox\LoginLink\Http\Middleware\ValidateLoginLink to protect routes:
      Route::get('/login-via-link', function () {
          // Protected logic here
      })->middleware('login-link');
      
    • Custom Logic: Extend the LoginLink class to add pre/post-validation hooks:
      class CustomLoginLink extends \Moox\LoginLink\LoginLink {
          protected function beforeValidation() {
              // Add custom checks (e.g., IP whitelisting)
          }
      }
      
  3. Blade Integration:

    • Default Component: <x-login-link /> (renders a clickable link).
    • Custom Views: Override the default view by publishing and modifying:
      php artisan vendor:publish --tag="login-link-views"
      
  4. Email Integration:

    • Attach links to emails using the LoginLink facade:
      $link = LoginLink::create();
      Mail::to($user)->send(new LoginLinkEmail($link));
      

Advanced Patterns

  • Rate Limiting: Combine with Laravel’s throttle middleware to limit link generation per user/IP.
  • Multi-Factor Auth (MFA): Use the expires_in parameter to enforce short-lived links for MFA flows.
  • Analytics: Log link usage via events:
    LoginLink::creating(function ($link) {
        event(new LoginLinkGenerated($link));
    });
    

Gotchas and Tips

Pitfalls

  1. Token Expiration:

    • Default lifetime is 15 minutes (configurable in login-link.php). Ensure this aligns with your security needs.
    • Debugging: Use php artisan tinker to inspect tokens:
      \Moox\LoginLink\Token::where('used', false)->get();
      
  2. CSRF Protection:

    • The package does not protect against CSRF for login links by default. Add middleware if needed:
      Route::middleware(['login-link', 'web'])->get('/protected-route');
      
  3. Database Conflicts:

    • If you customize the tokens table, ensure the token column is indexed for performance:
      Schema::table('login_link_tokens', function (Blueprint $table) {
          $table->index('token');
      });
      
  4. URL Validation:

    • The package validates URLs against configured patterns (e.g., allowed_domains in config). Misconfigurations may break link generation.

Debugging Tips

  • Log Link Events: Enable logging in config/login-link.php:

    'log_events' => env('LOGIN_LINK_LOG', false),
    

    Check storage/logs/laravel.log for token generation/usage.

  • Test Locally: Use php artisan login-link:test to simulate link generation and validation.

Extension Points

  1. Custom Token Storage: Override the Token model to use a different database or cache:

    class CustomToken extends \Moox\LoginLink\Token {
        protected $connection = 'pgsql';
    }
    
  2. Event Listeners: Listen for LoginLinkGenerated, LoginLinkUsed, or LoginLinkExpired events to trigger custom logic (e.g., notifications).

  3. API Responses: Extend the LoginLink class to return additional data:

    public function getExtraData() {
        return ['custom_field' => 'value'];
    }
    
  4. Internationalization: Publish and translate the Blade component:

    php artisan vendor:publish --tag="login-link-views" --provider="Moox\LoginLink\LoginLinkServiceProvider"
    

    Then override resources/views/vendor/login-link/link.blade.php.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle