esplora/auto-login

Enables seamless autologin functionality via temporary links, providing convenient and secure access to your application.

1.0.0 2023-07-22 00:59 UTC

This package is auto-updated.

Last update: 2024-04-04 14:11:03 UTC


README

The AutoLogin package for Laravel enables seamless autologin functionality via temporary links. Empower your users with convenient access to your application by securely logging them in using time-limited, temporary autologin links.

Installation

You can install AutoLogin in your project using the Composer package manager:

composer require esplora/auto-login

Usage

To get started with the AutoLogin package, follow the steps below:

  1. Add the route for autologin in your routes/web.php file:
use Esplora\AutoLogin\AutoLogin;

AutoLogin::routes();

This will register the necessary route for autologin functionality.

  1. Create temporary autologin links in your controllers, emails, or other relevant places using the following methods:
AutoLogin::to('/path');
// or use named routes
AutoLogin::route('telescope', [
    'active' => '1'
]);

These methods will generate temporary links that automatically log in the user. By default, the current authenticated user will be used. However, if the code is executed in the console or in a non-authenticated context, you need to pass the user ID as the second argument:

AutoLogin::to('/path', 123);
// or use named routes
AutoLogin::route('telescope', [
    'active' => '1'
], 123);

Configuration

The AutoLogin package provides some configuration options to suit your needs. By default, the autologin URL is set to /autologin. However, if you have changed this route usage, you can specify the desired URL using the following method:

use Esplora\AutoLogin\AutoLogin;

AutoLogin::routes('/your/path/autologin');

Additionally, you can specify a Blade template to customize the autologin view. Simply pass the desired template path as the second argument:

use Esplora\AutoLogin\AutoLogin;

AutoLogin::routes('/your/path/autologin', 'path.for.your.blade.template');

In your custom template, you can access the link variable, which contains the autologin URL, and use it as needed.

<!-- path.for.your.blade.template -->

<!doctype html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Redirecting...</title>

    <script type="text/javascript">
      setTimeout(function () {
        window.location.href = "{{ $link }}";
      }, 3000);
    </script>
  </head>
  <body>
    <h1>You are being redirected</h1>

    <p>You will be redirected to an external page in a few seconds.</p>

    <p>
      If you are not redirected automatically, please click
      <a href="{{ $link }}">here</a>.
    </p>
  </body>
</html>

License

The MIT License (MIT). Please see License File for more information.