new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Better Auth · Plugins · all subjects

one-time token plugin

11 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

One-Time Token plugin installation in auth config

To use the One-Time Token plugin, import oneTimeToken from 'better-auth/plugins/one-time-token' and add it to the plugins array in the betterAuth config.

One-Time Token client plugin installation

Import oneTimeTokenClient from 'better-auth/client/plugins' and add it to the plugins array in the createAuthClient config.

Generate one-time token endpoint

The /one-time-token/generate endpoint is a GET request that requires an active session. It returns a token attached to the current session. Call it using auth.api.generateOneTimeToken or authClient.oneTimeToken.generate.

One-time token default expiration time

By default, one-time tokens expire in 3 minutes.

Verify one-time token endpoint

The /one-time-token/verify endpoint is a POST request that takes a token parameter (string, required). It returns the session that was attached to the token. Call it using auth.api.verifyOneTimeToken or authClient.oneTimeToken.verify.

One-Time Token plugin configuration options

The oneTimeToken plugin accepts the following configuration options: disableClientRequest (boolean, optional, default false) - if true, token generation is server-side only; expiresIn (number, optional, default 3) - token validity duration in minutes; generateToken - custom token generator function taking session and ctx parameters; storeToken (optional) - configures how the token is stored in the database using 'plain', 'hashed', or a custom-hasher function.

One-Time Token storeToken plain option

When storeToken is set to 'plain', the token is stored in plain text in the database. This is the default behavior. The actual token sent to the user is not affected.

One-Time Token storeToken hashed option

When storeToken is set to 'hashed', the token is hashed using the default hasher before being stored in the database. The actual token sent to the user is not affected.

One-Time Token custom hasher configuration

The storeToken option accepts a custom hasher by setting type to 'custom-hasher' and providing a hash function that takes a token and returns a hashed token. Only the stored token is affected; the token sent to the user remains unchanged.

One-Time Token plugin use case

The One-Time Token plugin provides functionality to generate and verify secure, single-use session tokens, commonly used for across-domains authentication.

One-Time Token expiresIn configuration example

To set a custom token expiration time, use oneTimeToken({ expiresIn: 10 }) to set the token to expire in 10 minutes.

Give your agent this brain