A Blade component to quickly login to your local environment

Overview

Quickly login to your local environment

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

When developing an app that has an admin section (or any non-public section), you'll likely seed test users to login. In large teams that work on many different apps it can be cumbersome to keep track of the right credentials. Is the user account "[email protected]", or "[email protected]", or even "[email protected]"? Is that password "password", or "secret", or something is else? How do I login with a user that has a different role?

This package solves that problem by offering a component that will render a login link. When clicked, that link will log you in.

In your login view, you can add the x-login-link component to show the login link. The @env('local') will make sure that the links are only rendered in the local environment.

@endenv">
@env('local')
    <div class="space-y-2">
        <x-login-link email="[email protected]" label="Login as admin"/>
        <x-login-link email="[email protected]" label="Login as regular user"/>
    div>
@endenv

Here's what that might look like in the browser:

screenshot

It is meant for local development, and probably shouldn't be used in any publicly reachable environment.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer.

composer require spatie/laravel-login-link

Optionally, you can publish the config file with:

php artisan vendor:publish --tag="login-link-config"

This is the contents of the published config file:

use Spatie\LoginLink\Http\Controllers\LoginLinkController;

return [
    /*
     * Login links will only work in these environments. In all
     * other environments, an exception will be thrown.
     */
    'allowed_environments' => ['local'],

    /*
     * The package will automatically create a user model when trying
     * to log in a user that doesn't exist.
     */
    'automatically_create_missing_users' => true,

    /*
     * The user model that should be logged in. If this is set to `null`
     * we'll take a look at the model used for the `users`
     * provider in config/auth.php
     */
    'user_model' => null,

    /*
     * After a login link is clicked, we'll redirect the user to this route.
     * If it is set to `null` , we'll redirect to `/`.
     */
    'redirect_route_name' => null,

    /*
     * The package will register a route that points to this controller. To have fine
     * grained control over what happens when a login link is clicked, you can
     * override this class.
     */
    'login_link_controller' => LoginLinkController::class,

    /*
     * This middleware will be applied on the route
     * that logs in a user via a link.
     */
    'middleware' => ['web'],
];

Optionally, you can publish the views using

php artisan vendor:publish --tag="login-link-views"

Usage

To render a login link, simply add the x-login-link Blade component to your view. We highly recommend to only render it in the local environment.

@env('local')
    <x-login-link />
@endenv

This component will render a link that, when clicked, will log you in. By default, it will redirect you to /, but you can customize that by specifying a route name in the redirect_route_name of the login-link config file.

You can also specify the redirect URL on the component itself:

">
<x-login-link redirect-url="{{ route('dashboard') }}"  />

Specifying the user model to log in

By default, it will use the user model class that is specified in the providers.users.model key of the auth config file. To override this, you can set the user_model of the login-link config file to the class name of your user model.

The package will log in the first user in the table. You customize that by passing an email attribute. The user with that mail address will be logged in.

">
<x-login-link email="[email protected]"  />

Alternatively, you can specify the primary key of the user (in most cases this will be the id)

">
<x-login-link id="123"  />

You can also specify the attributes of the user that needs to be logged in.

'admin']" />">
<x-login-link :user-attributes="['role' => 'admin']"  />

Customizing the login link

By default, the package will display "Developer login" as the text of the login link. You can customize that by passing a label attribute.

">
<x-login-link label="Click here to log in">

A login link will have the Tailwind class underline by default. To customize that, you can pass any css class that you want to the class property. These classes will override the underline default.

Here's how you can create a red, underlined link (when using Tailwind CSS).

">
<x-login-link class="underline text-red-500">

Specifying the login guard

By default, the package will use the default guard. You can specify another guard.

">
<x-login-link guard="admin">

Automatic user creation

If the user that needs to be logged in does not exist, the package will use the factory of your user model to create the user, and log that new user in.

If you don't want this behaviour, set automatically_create_missing_users in the local-link config file to false.

Usage with Vue / React / ...

The package doesn't come with any JS component out of the box. When you use a JS front end framework to render your views, you can still make use of the package.

You should send a POST request to /laravel-login-link-login. If you don't give it any payload, then it will log in the first user in your users table. If there is no user, it will be created.

Optionally, you can post any of these payload fields. The functionality of these payloads fields match those of the attributes that you can pass to x-login-link component.

  • email: attempt to log in the user with the given email address
  • key: attempt to log in the user with the given key (in most cases the id of the users)
  • redirect_url: to which URL should we redirect after logging in
  • user_attributes: an array containing the attributes that the user that will be logged in needs to have.

Since this is a POST request, make sure to pass a CSRF token as well.

Usage in other environments

Out of the box, the login link will only work in a local environment. If you want to use it other environments, set the allowed_environments key of the login-link config file to the names of those environments.

Beware however, that you should never display login links in any environment that is publicly reachable, as it will allow anyone to log in.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

Comments
Releases(1.1.1)
  • 1.1.1(Jul 14, 2022)

    What's Changed

    • Bump dependabot/fetch-metadata from 1.3.1 to 1.3.3 by @dependabot in https://github.com/spatie/laravel-login-link/pull/9
    • Redirect users to the requested page after login by @VenomXL in https://github.com/spatie/laravel-login-link/pull/11

    New Contributors

    • @dependabot made their first contribution in https://github.com/spatie/laravel-login-link/pull/9
    • @VenomXL made their first contribution in https://github.com/spatie/laravel-login-link/pull/11

    Full Changelog: https://github.com/spatie/laravel-login-link/compare/1.1.0...1.1.1

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Jun 1, 2022)

    What's Changed

    • Update README.md by @gruzker in https://github.com/spatie/laravel-login-link/pull/4
    • Allow to specify the guard name by @sdebacker in https://github.com/spatie/laravel-login-link/pull/5

    New Contributors

    • @gruzker made their first contribution in https://github.com/spatie/laravel-login-link/pull/4
    • @sdebacker made their first contribution in https://github.com/spatie/laravel-login-link/pull/5

    Full Changelog: https://github.com/spatie/laravel-login-link/compare/1.0.1...1.1.0

    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Jun 1, 2022)

  • 1.0.0(May 30, 2022)

  • 0.0.3(May 28, 2022)

  • 0.0.2(May 27, 2022)

  • 0.0.1(May 27, 2022)

Owner
Spatie
We create open source, digital products and courses for the developer community
Spatie
It's authorization form, login button handler and login to your personal account, logout button

Authorization-form It's authorization form, login button handler and login to your personal account, logout button Each file is: header.php - html-fil

Galina 2 Nov 2, 2021
Provides a unified interface to local and remote authentication systems.

Aura.Auth Provides authentication functionality and session tracking using various adapters; currently supported adapters are: Apache htpasswd files S

Aura for PHP 125 Sep 28, 2022
Quickly create `User` models with Artisan. ⚡️

Quickly create User models with Artisan. Installation You can install the package via composer: composer require ryangjchandler/laravel-make-user Usag

Ryan Chandler 14 Oct 7, 2022
Prevents development packages from being added into require and getting into production environment.

production-dependencies-guard Prevents development packages from being added into require and getting into production environment. In practical field

Vladimir Reznichenko 88 Oct 21, 2022
Minimal Laravel authentication scaffolding with Blade and Tailwind.

Introduction Breeze provides a minimal and simple starting point for building a Laravel application with authentication. Styled with Tailwind, Breeze

The Laravel Framework 2.1k Jan 3, 2023
Instantly login as user via a single button tap on dev environments.

Getting tired of always entering login details in local dev environments? This package adds a button to instantly login a user! Installation You can i

Quinten Buis 3 Feb 18, 2022
A whitelabeled and modernized wp-login.php

Modern Login Here lives a simple mu-plugin to whitelabel and modernize wp-login.php. No admin panels, no bloat – just a simple filter to optionally cu

Brandon 65 Dec 22, 2022
A Laravel 5 package for OAuth Social Login/Register implementation using Laravel socialite and (optionally) AdminLTE Laravel package

laravel-social A Laravel 5 package for OAuth Social Login/Register implementation using Laravel socialite and (optionally) AdminLTE Laravel package. I

Sergi Tur Badenas 42 Nov 29, 2022
Braindead simple social login with Laravel and Eloquent.

Important: This package is not actively maintained. For bug fixes and new features, please fork. Eloquent OAuth Use the Laravel 4 wrapper for easy int

Adam Wathan 374 Dec 21, 2022
Un proyecto que crea una API de usuarios para registro, login y luego acceder a su información mediante autenticación con JSON Web Token

JSON WEB TOKEN CON LARAVEL 8 Prueba de autenticación de usuarios con una API creada en Laravel 8 Simple, fast routing engine. License The Laravel fram

Yesser Miranda 2 Oct 10, 2021
User registration and login form with validations and escapes for total security made with PHP.

Login and Sign Up with PHP User registration and login form with validations and escapes for total security made with PHP. Validations Required fields

Alexander Pérez 2 Jan 26, 2022
Register ,Login , Logout , having access control

Helo what's up dude read by the name of creator lov3yp :D This script is inspired by Lov3yp#2018 And Burak karahan Installation steps: !- Import the s

Lov3yp 2 Nov 1, 2021
Laravel package to easily login as other users during development.

A Laravel 5.4 utility package to enable developers to log in as other users during development. Installation To install the package, simply follow the

VIA Creative 555 Jan 8, 2023
A complete Login and Register page using a Mysql Database and php

Login With Mysql A complete Login and Register page using a Mysql Database ?? Built with ⚙️ ?? Description A login with Frontend, Backend and Database

Marc Medrano 1 Nov 5, 2021
Login Using Laravel UI

Projeto Laravel utilizando a biblioteca Laravel UI para autenticação de usuários com Username e Senha.

AlexLeonel 2 Oct 27, 2021
Login & Register using laravel 8

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Georgy Octavianus Fernando 1 Nov 16, 2021
PHP Login and Registration Script

dj_login PHP Login and Registration Script To function this script requires you put your MySQL info into both login.php and register.php, and have the

djsland.com 1 Nov 16, 2021
This extension expands WSOAuth extension and provide a EveOnline SSO login method

This extension expands WSOAuth extension and provide a EveOnline SSO login method

Raze Soldier 1 Nov 15, 2021
A simple, safe magic login link generator for Laravel

Laravel Passwordless Login A simple, safe magic login link generator for Laravel This package provides a temporary signed route that logs in a user. W

gro.sv 689 Dec 25, 2022