Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/docs/content/docs/offer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To stay up-to-date with the current progress of Better-Auth-Kit, you can track o
- [Reverify](/docs/plugins/reverify) - A plugin to reverify a user's identity.
- [Legal Consent](/docs/plugins/legal-consent) - A plugin to collect legal consent from your users. (Coming Soon)
- [Blockade](/docs/plugins/blockade) - A plugin to blacklist or whitelist users from accessing your application. (Coming Soon)
- [Shutdown](/docs/plugins/shutdown) - A plugin to stop signins or signups at any moment, such as for maintenance. (Coming Soon)
- [Shutdown](/docs/plugins/shutdown) - A plugin to stop signins or signups at any moment, such as for maintenance.

## Libraries

Expand Down
214 changes: 210 additions & 4 deletions apps/docs/content/docs/plugins/shutdown.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,213 @@ description: Stop signins or signups at any moment.
<GithubButton url="https://github.com/ping-maxwell/better-auth-kit/tree/main/packages/plugins/shutdown" />
<NpmButton url="https://www.npmjs.com/package/@better-auth-kit/shutdown" />

<Callout type="warn">
#### This plugin is not yet available.
View our [roadmap](/roadmap) to see what is coming soon.
</Callout>
<Steps>
<Step>
### 1. Install the plugin

```package-install
@better-auth-kit/shutdown
```

</Step>

<Step>
### 2. Initialize the plugin

<Tabs items={["Single Instance/Serverless", "Multiple Instances"]}>

<Tab value="single-instance/serverless">
```ts title="auth.ts"
import { shutdown } from "@better-auth-kit/shutdown";

export const auth = betterAuth({
plugins: [shutdown({
/*
* Roles allowed to add shutdown rules
* @default: ["admin"]
*/
allowedRoles: ["admin"],
})]
});
```
</Tab>
<Tab value="multiple-instances">

When there are multiple instances of the application, the plugin needs to be initialized with a cache that can be revalidated when rules changes. Below there is an example using **Redis**.

```ts title="auth.ts"
import { shutdown } from "@better-auth-kit/shutdown";
import Redis from "ioredis";

const redis = new Redis();

const cache = {
requireRevalidation: (cb) => {
// subscribe only to the shutdown-rules channel
redis.subscribe("shutdown-rules");
// trigger the callback when a message is received
redis.on("message", (channel, message) => cb());
}
onRulesChanged: () => {
redis.publish("shutdown-rules", "sync")
}
};

export const auth = betterAuth({
plugins: [shutdown({
/*
* Roles allowed to add shutdown rules
* @default: ["admin"]
*/
allowedRoles: ["admin"],
})]
});
```
</Tab>
</Tabs>

</Step>
<Step>
### 3. Rules Management

These methods can be called only by the users with `allowedRoles`.

<Tabs items={["List", "Create", "Remove"]} updateAnchor>

<Tab id="list-rules" value="list">
```ts
const data = await auth.api.listShutdownRules({
headers,
});

/*
[
{
id: "XGH61HHHL0s3d3cug7IH2wrIqic1fJ7r",
roles: ["user"],
signUp: true,
signIn: true,
from: new Date(),
to: new Date(),
},
]
*/
console.log(data)
```
</Tab>

<Tab id="create-rule" value="create">
```ts
const data = await auth.api.createShutdownRule({
body: {
/*
* Disallow sign-up for the given roles
* @default: true
*/
signUp: true,
/*
* Disallow sign-in for the given roles
* @default: true
*/
signIn: true,
/*
* The roles to apply the shutdown rule to
* @default: []
*/
roles: ["user"],
/*
* The date to start the shutdown rule
* @default: null
*/
from: new Date(),
/*
* The date to end the shutdown rule
* @default: null
*/
to: new Date()
},
headers,
});

const isAdded = data?.success;
const ruleId = data?.ruleId;
```
</Tab>

<Tab id="remove-rule" value="remove">
```ts
const data = await auth.api.removeShutdownRule({
body: {
/*
* The rule id to remove
*/
id: "$ruleId",
},
headers,
});

const isRemoved = data?.success;
```
</Tab>

</Tabs>

</Step>

<Step>
### 4. Check if sign-in / sign-up is allowed

You can also check if sign-up is allowed. E.g. hide a signup page or show an alert.

#### Sign In
```ts
const { allowed } = await auth.api.isSignInAllowed();
```

#### Sign Up

```ts
const { allowed } = await auth.api.isSignUpAllowed();
```

</Step>

</Steps>

<div className="h-10" />

## Schema

Table: `shutdown-rules`

<DatabaseTable
fields={[
{
name: "roles",
type: "string",
description: "Roles to apply the shutdown rule to.",
},
{
name: "signin",
type: "boolean",
description:
"Wether to disable sign in for the given roles or by the time range",
},
{
name: "signUp",
type: "boolean",
description:
"Wether to disable sign-up in for the given roles or by the time range",
},
{
name: "from",
type: "date",
description: "The date to start the shutdown rule.",
},
{
name: "to",
type: "date",
description: "The date to end the shutdown rule.",
},
]}
/>
1 change: 0 additions & 1 deletion apps/docs/src/components/sidebar-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export const contents: Content[] = [
href: "/docs/plugins/shutdown",
title: "Shutdown",
icon: () => <OctagonMinus size={16} />,
isNotReady: true,
},
{
title: "Libraries",
Expand Down
20 changes: 18 additions & 2 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@
},
"packages/adapters/convex": {
"name": "@better-auth-kit/convex",
"version": "1.1.0",
"version": "1.2.2",
"dependencies": {
"prettier": "^3.4.2",
},
"devDependencies": {
"@better-auth-kit/internal-build": "workspace:*",
"@biomejs/biome": "1.9.4",
"@changesets/cli": "^2.27.11",
"@types/node": "^22.10.5",
Expand Down Expand Up @@ -154,7 +155,7 @@
},
"packages/libraries/seed": {
"name": "@better-auth-kit/seed",
"version": "1.0.6",
"version": "1.0.10",
"dependencies": {
"better-auth": "^1.2.4",
"chalk": "^5.4.1",
Expand Down Expand Up @@ -230,6 +231,19 @@
"better-auth": "^1.1.21",
},
},
"packages/plugins/shutdown": {
"name": "@better-auth-kit/shutdown",
"version": "0.0.1",
"dependencies": {
"zod": "^3.24.2",
},
"devDependencies": {
"@better-auth-kit/internal-build": "workspace:*",
},
"peerDependencies": {
"better-auth": "^1.2.1",
},
},
"packages/plugins/waitlist": {
"name": "@better-auth-kit/waitlist",
"version": "0.0.6",
Expand Down Expand Up @@ -331,6 +345,8 @@

"@better-auth-kit/seed": ["@better-auth-kit/seed@workspace:packages/libraries/seed"],

"@better-auth-kit/shutdown": ["@better-auth-kit/shutdown@workspace:packages/plugins/shutdown"],

"@better-auth-kit/tests": ["@better-auth-kit/tests@workspace:packages/libraries/tests"],

"@better-auth-kit/waitlist": ["@better-auth-kit/waitlist@workspace:packages/plugins/waitlist"],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev --concurrency 11",
"dev": "turbo run dev --concurrency 12",
"format": "biome format --write",
"lint": "biome lint",
"check-types": "turbo run check-types",
Expand Down
Loading