forked from XiaoMo/ChatGPT-Next-Web
37 lines
816 B
TypeScript
37 lines
816 B
TypeScript
import { create } from "zustand";
|
|
import { persist } from "zustand/middleware";
|
|
import { queryMeta } from "../utils";
|
|
|
|
export interface AccessControlStore {
|
|
accessCode: string;
|
|
token: string;
|
|
|
|
updateToken: (_: string) => void;
|
|
updateCode: (_: string) => void;
|
|
enabledAccessControl: () => boolean;
|
|
}
|
|
|
|
export const ACCESS_KEY = "access-control";
|
|
|
|
export const useAccessStore = create<AccessControlStore>()(
|
|
persist(
|
|
(set, get) => ({
|
|
token: "",
|
|
accessCode: "",
|
|
enabledAccessControl() {
|
|
return queryMeta("access") === "enabled";
|
|
},
|
|
updateCode(code: string) {
|
|
set((state) => ({ accessCode: code }));
|
|
},
|
|
updateToken(token: string) {
|
|
set((state) => ({ token }));
|
|
},
|
|
}),
|
|
{
|
|
name: ACCESS_KEY,
|
|
version: 1,
|
|
}
|
|
)
|
|
);
|