This commit is contained in:
2026-04-10 15:37:02 +08:00
parent 161cd32277
commit f19e482c8f
233 changed files with 43987 additions and 5127 deletions

View File

@@ -0,0 +1,32 @@
import crypto from 'node:crypto';
export type WechatAuthStateRecord = {
state: string;
redirectPath: string;
createdAt: string;
};
export class WechatAuthStateStore {
private readonly states = new Map<string, WechatAuthStateRecord>();
create(redirectPath: string) {
const state = crypto.randomBytes(18).toString('hex');
const record: WechatAuthStateRecord = {
state,
redirectPath,
createdAt: new Date().toISOString(),
};
this.states.set(state, record);
return record;
}
consume(state: string) {
const record = this.states.get(state) ?? null;
if (!record) {
return null;
}
this.states.delete(state);
return record;
}
}