Skip to content

About

One-click login buttons on the Kirby Panel login, for local development

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Kirby Dev Login

Kirby 5 and 6 · PHP 8.2–8.5 (Kirby 6: 8.3–8.5) · MIT

One-click login for local development: the Panel's login form gets a button per account, which logs that account in without a password. Handy when you switch between roles all day.

Kirby's login form stays as it is; the buttons sit below it. The plugin uses Kirby's own extension points, no DOM patching: on Kirby 5 its login form plugin (panel.plugin(…, { login })), on Kirby 6, which has none, an extension of the list of other login methods below the form (k-login-methods).

The Panel's login form with a button per account below it: Mara Lind (Admin), Tom Ruiz (Client), Jonas Weber (Editor), Priya Nair (Editor)

Safe by default

The buttons, and the two API routes behind them, only exist when

  • debug is true, and
  • the site runs on a local host (Kirby's $kirby->environment()->isLocal(): localhost, *.local, *.test, *.ddev.site, or every visitor IP is 127.0.0.1/::1).

Otherwise the routes answer 404 and the login form looks as always. Only accounts with Panel access get a button. A login still needs the Panel's CSRF token, like Kirby's own login route.

Similar concepts and plugins

  • Kirby Impersonate by nerdcel: admins (or allowed roles) view the Panel as another user from a button on that user's profile page, also on a live site. You log in first, and the impersonation runs within your own session until you end it. It checks what a user sees; Dev Login skips the login while you develop. The two work side by side.
  • Kirby Autologin by Jens Törnell, for Kirby 2 and no longer maintained: on localhost, visiting /login or /login/<username> logged you into the Panel without a password. Dev Login brings the idea to Kirby 5 and 6, with a button per account instead of a URL to know.
  • The Kirby team's test environment for Kirby itself (not a plugin) logs its test accounts in through a URL (/env/auth/<email>) and has a dialog in the Panel to switch to another account once you are logged in.

Install

Composer

composer require --dev volkmann-design-code/kirby-dev-login

As a dev dependency it stays out of deployments built with composer install --no-dev.

Git submodule

git submodule add https://github.com/volkmann-design-code/kirby-dev-login.git site/plugins/dev-login

Download

Download the latest release and unzip it into site/plugins/dev-login.

Without Composer, make sure the plugin doesn't reach your live site, e.g. by leaving site/plugins/dev-login out of the deployment. It stays off there anyway unless debug is on and the host is local.

Kirby lets one plugin replace the login form (Kirby 5) or a Panel component (Kirby 6), so this plugin can't be combined with another that replaces the login form or k-login-methods. On Kirby 6, the browser console says Plugin is replacing "k-login-methods"; that's this plugin.

Usage

Turn on debug in your local config and open the Panel's login page:

// site/config/config.localhost.php
return ['debug' => true];

Below the login form, click an account to log in as it. On Kirby 6 the buttons show for every login method (auth.methods), below the buttons for the other methods, and not while Kirby asks for a second factor.

Options

// site/config/config.php
return [
	'volkmann-design-code.dev-login' => [
		// null (default): on with `debug` on a local host;
		// or true, false, or fn (Kirby\Cms\App $kirby): bool
		'enabled'     => null,
		// null (default): every account with Panel access;
		// or fn (Kirby\Cms\App $kirby): Kirby\Cms\Users|array of emails
		'users'       => null,
		// true: a card per account with its role's description
		'description' => false,
		// true: the accounts first, Kirby's login form behind a button
		'collapse'    => false,
	],
];

Buttons are sorted by role, then name; each shows the name and, in parentheses, the role (just the name when both are the same); the email on hover.

With description, each account is a card instead (Kirby's cardlet layout) that also shows its role's description from the user blueprint, for example to explain the roles of a public demo.

With collapse, the accounts come first and Kirby's login form opens from a button below them ("Log in with email"), for sites where most people log in with a click and a few still need the form.

How it works

  • GET /api/dev-login: the accounts (email, name, role, and with the description option the role's description), and collapse
  • POST /api/dev-login with email: $user->loginPasswordless()
  • index.js, on Kirby 5: the login form plugin. It renders Kirby's k-login-form and the buttons below. Written with render functions, so it works without the Panel's template compiler (panel.vue.compiler: false).
  • index.js, on Kirby 6: extends k-login-methods, which Kirby's login view shows below the form; it renders Kirby's component, then the buttons. Kirby 6 always ships Vue's template compiler. With collapse, index.css moves the accounts above the form and hides the form until its button is clicked.
  • Which of the two: Kirby 5 exposes its Vue 2 as window.Vue, Kirby 6 doesn't. One file for both.

Languages

The label above the buttons comes in English and German, and falls back to English in other Panel languages; role titles are translated by Kirby. More languages are welcome as a pull request (index.php).

Development

composer install    # Kirby into kirby/, PHPUnit
composer test

composer install picks Kirby 6 on PHP 8.3 and newer. For Kirby 5:

composer update --with "getkirby/cms:^5.0"

The cover images .github/cover.png (2:1) and .github/cover-square.png (1:1) are rendered from a real Panel with made-up accounts, the same on every run (pinned Chromium and fonts). They show Kirby 5's login, so install Kirby 5 first (see above):

cd .github/cover
npm ci && npx playwright install chromium
npm run cover

License

MIT, see LICENSE. By volkmann design code.

About

One-click login buttons on the Kirby Panel login, for local development

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages