mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
Add login key system
This commit is contained in:
@@ -2,16 +2,16 @@ import { useState } from 'react';
|
||||
import { toast } from 'react-toastify';
|
||||
import Cookies from 'js-cookie';
|
||||
import { anthropicNumFreeUsesCookieName, anthropicApiKeyCookieName, MaxFreeUses } from '~/utils/freeUses';
|
||||
import { setNutAdminKey, setProblemsUsername, getNutAdminKey, getProblemsUsername } from '~/lib/replay/Problems';
|
||||
import { saveNutLoginKey, saveProblemsUsername, getNutLoginKey, getProblemsUsername } from '~/lib/replay/Problems';
|
||||
|
||||
export default function ConnectionsTab() {
|
||||
const [apiKey, setApiKey] = useState(Cookies.get(anthropicApiKeyCookieName) || '');
|
||||
const [username, setUsername] = useState(getProblemsUsername() || '');
|
||||
const [adminKey, setAdminKey] = useState(getNutAdminKey() || '');
|
||||
const [loginKey, setLoginKey] = useState(getNutLoginKey() || '');
|
||||
const numFreeUses = +(Cookies.get(anthropicNumFreeUsesCookieName) || 0);
|
||||
|
||||
const handleSaveAPIKey = async (key: string) => {
|
||||
if (!key || !key.startsWith('sk-ant-')) {
|
||||
if (key && !key.startsWith('sk-ant-')) {
|
||||
toast.error('Please provide a valid Anthropic API key');
|
||||
return;
|
||||
}
|
||||
@@ -21,13 +21,19 @@ export default function ConnectionsTab() {
|
||||
};
|
||||
|
||||
const handleSaveUsername = async (username: string) => {
|
||||
setProblemsUsername(username);
|
||||
saveProblemsUsername(username);
|
||||
setUsername(username);
|
||||
};
|
||||
|
||||
const handleSaveAdminKey = async (key: string) => {
|
||||
setNutAdminKey(key);
|
||||
setAdminKey(key);
|
||||
const handleSaveLoginKey = async (key: string) => {
|
||||
setLoginKey(key);
|
||||
|
||||
try {
|
||||
await saveNutLoginKey(key);
|
||||
toast.success('Login key saved');
|
||||
} catch (error) {
|
||||
toast.error('Failed to save login key');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -61,13 +67,13 @@ export default function ConnectionsTab() {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">Nut Admin Key</h3>
|
||||
<h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">Nut Login Key</h3>
|
||||
<div className="flex mb-4">
|
||||
<div className="flex-1 mr-2">
|
||||
<input
|
||||
type="text"
|
||||
value={adminKey}
|
||||
onChange={(e) => handleSaveAdminKey(e.target.value)}
|
||||
value={loginKey}
|
||||
onChange={(e) => handleSaveLoginKey(e.target.value)}
|
||||
className="w-full bg-white dark:bg-bolt-elements-background-depth-4 relative px-2 py-1.5 rounded-md focus:outline-none placeholder-bolt-elements-textTertiary text-bolt-elements-textPrimary dark:text-bolt-elements-textPrimary border border-bolt-elements-borderColor disabled:opacity-50"
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user