@mottyjs /身份验证
Motty SDK的插件。 auth() 将调用者置于上下文中并拒绝的部分是否为
请求主机无法识别。它自己没有检查:主机的验证适配器证明
调用者,以及证明它从未到达motty的密钥或令牌。
bun add @mottyjs/auth
import { auth } from "@mottyjs/auth";
一扇门,拒绝超过一天的限制的访客:
import { motty, QuotaExceeded } from "@mottyjs/core";
import { auth } from "@mottyjs/auth";
import { store } from "@mottyjs/store";
// The day is part of the key, so a new day starts at nothing and no reset has to run
const spendKey = (callerId: string) =>
`spend:${callerId}:${new Date().toISOString().slice(0, 10)}`;
export const dailyLimit = motty({ name: "daily-limit" })
.use(auth())
.beforeHandle(async ({ caller }) => {
if (((await store.get<number>(spendKey(caller.id))) ?? 0) >= 5) {
throw new QuotaExceeded("Today's limit of $5 is spent");
}
});
SDK作为一个整体在 根的自述,以及其设计背后的原因 ARCHITECTURE.md.