Last Login Method
Remember and highlight the auth method a user signed in with last.
On every successful sign-in, Kernia writes a browser-readable cookie naming the
method that was used (email, google, github, passkey, …). Your sign-in
page reads it on the next visit to surface a "Last used" badge on the right
button. It can optionally persist the method on the user row.
Installation
Add the plugin to your server
Pass last_login_method() to your Kernia config.
from kernia import KerniaOptions
from kernia.auth import init
from kernia.plugins.last_login_method import last_login_method
auth = init(KerniaOptions(
database=adapter,
secret=os.environ["KERNIA_SECRET"],
base_url=os.environ["KERNIA_BASE_URL"],
plugins=[last_login_method()],
))Add the client plugin
Add the lastLoginMethod client plugin so the helpers can read the cookie:
import { createAuthClient } from "better-auth/client";
import { lastLoginMethodClient } from "better-auth/client/plugins";
export const authClient = createAuthClient({
baseURL: "/api/auth",
plugins: [lastLoginMethodClient()],
});Usage
Read the last used method
const method = authClient.getLastUsedLoginMethod(); // "google" | "email" | nullUse the result to render a "Last used" badge on your sign-in page.
Check a specific method
if (authClient.isLastUsedLoginMethod("google")) {
// highlight the "Continue with Google" button
}Clear the stored method
authClient.clearLastUsedLoginMethod();Options
| Option | Type | Default | Description |
|---|---|---|---|
cookie_name | str | "better-auth.last_used_login_method" | Cookie that stores the method. Must match the client cookieName. |
max_age | int | 2592000 (30 days) | Cookie lifetime in seconds. |
store_in_database | bool | False | Also persist the method on user.lastLoginMethod. |
custom_resolve_method | (ctx) -> str | None | None | Override how the method is derived from the request. Returning None falls back to the default resolver. |
The default resolver recognises email sign-in/up, OAuth callbacks, SIWE, passkey, and magic-link paths.
Schema
By default the plugin only sets a cookie — no migration required. When
store_in_database=True, it extends the user table:
| Field | Type | Description |
|---|---|---|
lastLoginMethod | string (nullable) | The method used on the most recent successful sign-in. |
The cookie is intentionally not HTTP-only so your front-end can read it to highlight a button. It carries only a method name, never a token — never use it for authorization.