PlanetScale serverless adapter
Adapter for PlanetScale serverless driver provided by the MySQL adapter package.
import { planetscale } from "@lucia-auth/adapter-mysql";
const planetscale: (
connection: Connection,
tableNames: {
user: string;
key: string;
session: string | nul;
}
) => InitializeAdapter<Adapter>;
Parameters#
Table names are automatically escaped.
name | type | description |
---|---|---|
connection | Connection | PlanetScale serverless driver connection |
tableNames.user | string | User table name |
tableNames.key | string | Key table name |
tableNames.session | string | null | Session table name - can be null when using alongside a session adapter |
Installation#
npm i @lucia-auth/adapter-mysql
pnpm add @lucia-auth/adapter-mysql
yarn add @lucia-auth/adapter-mysql
Usage#
import { lucia } from "lucia";
import { planetscale } from "@lucia-auth/adapter-mysql";
import { connect } from "@planetscale/database";
const connection = connect({
host: "<host>",
username: "<user>",
password: "<password>"
});
const auth = lucia({
adapter: planetscale(connection, {
user: "auth_user",
key: "user_key",
session: "user_session"
})
// ...
});
MySQL schema#
You can choose any table names, just make sure to define them in the adapter argument. The id
columns are not UUID types with the default configuration.
User table#
You can add additional columns to store user attributes.
CREATE TABLE auth_user (
id VARCHAR(15) NOT NULL PRIMARY KEY,
);
Key table#
CREATE TABLE user_key (
id VARCHAR(255) NOT NULL PRIMARY KEY,
user_id VARCHAR(15) NOT NULL,
hashed_password VARCHAR(255),
);
Session table#
You can add additional columns to store session attributes.
CREATE TABLE user_session (
id VARCHAR(127) NOT NULL PRIMARY KEY,
user_id VARCHAR(15) NOT NULL,
active_expires BIGINT UNSIGNED NOT NULL,
idle_expires BIGINT UNSIGNED NOT NULL,
);