forked from ztjhz/BetterChatGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth-slice.ts
35 lines (33 loc) · 907 Bytes
/
auth-slice.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { defaultAPIEndpoint } from '@constants/auth';
import { StoreSlice } from './store';
export interface AuthSlice {
apiKey?: string;
apiEndpoint: string;
firstVisit: boolean;
setApiKey: (apiKey: string) => void;
setApiEndpoint: (apiEndpoint: string) => void;
setFirstVisit: (firstVisit: boolean) => void;
}
export const createAuthSlice: StoreSlice<AuthSlice> = (set, get) => ({
apiKey: import.meta.env.VITE_OPENAI_API_KEY || undefined,
apiEndpoint: defaultAPIEndpoint,
firstVisit: true,
setApiKey: (apiKey: string) => {
set((prev: AuthSlice) => ({
...prev,
apiKey: apiKey,
}));
},
setApiEndpoint: (apiEndpoint: string) => {
set((prev: AuthSlice) => ({
...prev,
apiEndpoint: apiEndpoint,
}));
},
setFirstVisit: (firstVisit: boolean) => {
set((prev: AuthSlice) => ({
...prev,
firstVisit: firstVisit,
}));
},
});