Skip to content

Commit

Permalink
apiKey migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jackschedel committed Feb 10, 2024
1 parent 18639ea commit 63ec8fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
11 changes: 11 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ function App() {
const setHideSideMenu = useStore((state) => state.setHideSideMenu);
const hideSideMenu = useStore((state) => state.hideSideMenu);
const bottomMessageRef = useStore((state) => state.bottomMessageRef);
const setApiAuth = useStore((state) => state.setApiAuth);
const apiAuth = useStore((state) => state.apiAuth);
const apiKey = useStore((state) => state.apiKey);
const setApiKey = useStore((state) => state.setApiKey);

const initialiseNewChat = useInitialiseNewChat();
const addChat = useAddChat();
Expand All @@ -30,6 +34,13 @@ function App() {
const copyCodeBlock = useCopyCodeBlock();
const { handleSubmit } = useSubmit();

if (apiKey && !apiAuth[0].apiKey) {
let old = apiAuth;

Check failure

Code scanning / ESLint

require `const` declarations for variables that are never reassigned after declared Error

'old' is never reassigned. Use 'const' instead.
old[0].apiKey = apiKey;
setApiAuth(old);
setApiKey('');
}

const handleGenerate = () => {
if (useStore.getState().generating) return;
const updatedChats: ChatInterface[] = JSON.parse(
Expand Down
5 changes: 1 addition & 4 deletions src/hooks/useSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ const useSubmit = () => {
if (!apiKey || apiKey.length === 0) {
// official endpoint
if (apiEndpoint === officialAPIEndpoint) {
const error = new Error(t('noApiKeyWarning') as string);
setError(error.message);
throw error;
throw new Error(t('noApiKeyWarning') as string);
}

// other endpoints
Expand Down Expand Up @@ -232,7 +230,6 @@ const useSubmit = () => {
}
} catch (e: unknown) {
setError((e as Error).message);
throw e;
}
setGenerating(false);
};
Expand Down
7 changes: 1 addition & 6 deletions src/store/auth-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ModelDefinition } from '@type/chat';
import { StoreSlice } from './store';

export interface AuthSlice {
apiKey?: string;
firstVisit: boolean;
apiAuth: EndpointAuth[];
modelDefs: ModelDefinition[];
Expand Down Expand Up @@ -44,12 +45,6 @@ export const createAuthSlice: StoreSlice<AuthSlice> = (set) => ({
apiKey: apiKey,
}));
},
setApiEndpoint: (apiEndpoint: string) => {
set((prev: AuthSlice) => ({
...prev,
apiEndpoint: apiEndpoint,
}));
},
setFirstVisit: (firstVisit: boolean) => {
set((prev: AuthSlice) => ({
...prev,
Expand Down

0 comments on commit 63ec8fa

Please sign in to comment.