npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

better-auth-idle-timeout

v1.0.1

Published

Idle timeout plugin for Better Auth

Readme

Better Auth Idle Timeout Plugin

The Idle Timeout plugin automatically expires and revokes sessions after a specified period of user inactivity (idle time). It tracks user activity and automatically terminates the session in the database if no activity is detected within a timeout window. To prevent database write-locking and reduce database load, the plugin includes write-throttling on activity updates.

Installation

1. Install the package

Install the package via your preferred package manager:

# Using bun
bun add better-auth-idle-timeout

# Using npm
npm install better-auth-idle-timeout

# Using pnpm
pnpm add better-auth-idle-timeout

2. Add the plugin to your auth config

To use the Idle Timeout plugin, add it to your server-side auth config:

import { betterAuth } from "better-auth"
import { idleTimeout } from "better-auth-idle-timeout"

export const auth = betterAuth({
    // ... other config options
    plugins: [
        idleTimeout({
            timeoutMinutes: 15,          // Optional: default is 15 minutes
            updateThrottleSeconds: 60    // Optional: default is 60 seconds
        })
    ]
})

3. Migrate the database

Run the migration or generate the schema to add the necessary fields to the database:

# Run migration
npx better-auth migrate

# Or generate schema
npx better-auth generate

See the Schema section to add the fields manually.

Options

timeoutMinutes

The period of inactivity (in minutes) after which a session is considered idle and gets revoked. Defaults to 15.

idleTimeout({
  timeoutMinutes: 30, // 30 minutes
})

updateThrottleSeconds

Cooldown period (in seconds) during which requests will not write a new lastActivityAt value to the database, reducing database load. Defaults to 60.

idleTimeout({
  updateThrottleSeconds: 120, // 2 minutes
})

How It Works

  1. Global Request Hook: A before hook interceptor runs on all incoming requests.
  2. Inactivity Assessment:
    • The plugin retrieves the session token from the signed session cookie.
    • It computes the time difference between the current time and the session's last activity (lastActivityAt or falls back to updatedAt).
    • If the inactive duration exceeds timeoutMinutes, the session is permanently deleted from the database and the request is rejected with an UNAUTHORIZED APIError containing the message "Session expired due to inactivity".
  3. Throttled Updates: If the session is active and valid, it updates the lastActivityAt timestamp in the database only if updateThrottleSeconds has elapsed since the last activity was recorded.

Schema

This plugin adds the following field to the session table:

| Field Name | Type | Description | | :--- | :--- | :--- | | lastActivityAt | Date (optional) | The timestamp of the user's last activity. Updates are throttled to prevent write lock on rapid subsequent requests. |


License

MIT © Jonathan