Settings: kscript.json
Every setting has a safe default, so set only what you want to change. Times are seconds, or text such as "15m", "2h" or "30d".
{
"types": { "password": { "min": 12 } },
"http": {
"auth": {
"login": "/login",
"home": "/",
"lifetime": "2h",
"remember": "30d",
"attempts": 5,
"lockout": "1m",
"reset_lifetime": "1h"
}
}
}| Setting | Default | What it does |
|---|---|---|
login |
/login |
Where auth sends people who aren't signed in. |
home |
/ |
Where guest sends people who are, and @intended()'s default. |
sessions |
file |
Where sessions, API tokens, reset tokens and passkey challenges are kept. file keeps them in the app's state folder, so they last across restarts. memory keeps them until kscript stops. database keeps them in the project's database, so every server shares them. See Sessions on several servers. |
auto_create |
true |
With sessions: database, false leaves making the kscript_sessions table to the project's migrations. |
folder |
the app folders | A folder, relative to the site, for users, sessions and tokens. |
users |
files | A KScript.Data model in the models folder, such as User, that holds the users. See Users in a model. |
lifetime |
2h |
How long a session lasts after the last request. |
remember |
30d |
How long a "remember me" sign-in lasts. |
cookie |
ks_session |
The session cookie's name. |
secure |
https only | true or false forces the cookie's Secure flag. |
same_site |
Lax |
The cookie's SameSite: Lax, Strict or None. |
csrf |
true |
false turns off the CSRF check. |
attempts |
5 |
Failed sign-ins allowed per email and address. |
lockout |
1m |
How long failures are counted over, and how long @attempt then waits. |
reset_lifetime |
1h |
How long a reset token works. |
passkey_origin |
disabled | The public HTTPS origin that can register and use passkeys. Local development accepts http://localhost with an optional port. |
passkey_signup |
false |
Allow a guest to create a passwordless account by verifying a new passkey. Requires passkey_origin. |
passkey_rp_id |
origin hostname | The relying party domain for credentials. |
passkeys |
file |
Where passkeys are kept: file (a SQLite file in the auth folder) or database (the project's database). See Passkeys in the database. |
confirm_within |
off | How recently someone must have signed in or checked a passkey to add or remove one, such as "5m". See Checking it's still them. |
passkey_remember |
false |
Keep a passkey sign-in for the remember time, not just the browser session. |
provider |
off | true, or settings, to sign people in to other apps. See Signing in to other apps. |
sign_in_with |
off | Settings to sign people in with another site's account. See Signing in with another site's account. |
guest_lifetime |
365d |
How long a browser keeps its @guest() id. |
guest_cookie |
ks_guest |
The guest id cookie's name. |
adopt_guest |
false |
true moves a guest's rows of Ownable models to their account when they sign in. |
token_env |
API_TOKEN |
The environment variable with the shared token the auth middleware also accepts. |
Sessions on several servers
With file or memory sessions, each server keeps its own, so a visitor whose requests reach two servers behind a load balancer is signed out on one of them. "sessions": "database" keeps sessions, API tokens, password reset tokens and the challenges of passkey sign-ins in one table of the project's database, kscript_sessions, that every server reads:
{ "http": { "auth": { "sessions": "database" } } }The table is made the first time it is needed. To make it with the project's migrations instead, run kscript publish sessions: it writes the migration, sets sessions to database and auto_create to false, and kscript db migrate then makes the table.
kscript publish sessions
kscript db migrateUsers stay where users says. A passkey challenge started on one server can be finished on another, but only once.
The password rules are the password type's, under types (see Types and validation). @register, @reset_password and ->set_password use them, and so do typed fields such as password: password in a type.