-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from smallcloudai/docker-authorization
WIP: api_key cookies
- Loading branch information
Showing
9 changed files
with
139 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React, { useEffect } from "react"; | ||
import { | ||
Flex, | ||
IconButton, | ||
Dialog, | ||
Text, | ||
TextField, | ||
Button, | ||
// DialogRoot, | ||
// DialogTrigger, | ||
// DialogContent, | ||
// DialogTitle, | ||
// DialogDescription, | ||
// DialogClose, | ||
} from "@radix-ui/themes"; | ||
import { GearIcon } from "@radix-ui/react-icons"; | ||
import { useApiKey } from "../../hooks"; | ||
|
||
export const Settings: React.FC = () => { | ||
const [apiKey, setApiKey] = useApiKey(); | ||
const [keyValue, setValue] = React.useState(apiKey); | ||
const [open, setOpen] = React.useState(false); | ||
|
||
useEffect(() => { | ||
setValue(apiKey); | ||
}, [apiKey, open]); | ||
|
||
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
setApiKey(keyValue); | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<Flex p="4"> | ||
<Dialog.Root open={open} onOpenChange={setOpen}> | ||
<Dialog.Trigger> | ||
<IconButton variant="outline" title="Settings"> | ||
<GearIcon /> | ||
</IconButton> | ||
</Dialog.Trigger> | ||
|
||
<Dialog.Content onOpenAutoFocus={(event) => event.preventDefault()}> | ||
<Dialog.Title>Settings</Dialog.Title> | ||
<Dialog.Description>Change chat settings</Dialog.Description> | ||
<Flex asChild pt="4"> | ||
<form onSubmit={handleSubmit}> | ||
<label style={{ width: "100%" }}> | ||
<Text as="div" size="2" mb="1" weight="bold"> | ||
API Key | ||
</Text> | ||
<TextField.Input | ||
name="apiKey" | ||
type="text" | ||
value={keyValue} | ||
onChange={(event) => setValue(event.target.value)} | ||
placeholder="Enter your refact api key" | ||
/> | ||
</label> | ||
</form> | ||
</Flex> | ||
<Flex gap="3" mt="4" justify="end"> | ||
<Dialog.Close> | ||
<Button variant="soft" color="gray"> | ||
Cancel | ||
</Button> | ||
</Dialog.Close> | ||
<Dialog.Close> | ||
<Button onClick={() => setApiKey(keyValue)} type="submit"> | ||
Save | ||
</Button> | ||
</Dialog.Close> | ||
</Flex> | ||
</Dialog.Content> | ||
</Dialog.Root> | ||
</Flex> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useState, useEffect } from "react"; | ||
import * as ApiKey from "../utils/ApiKey"; | ||
|
||
export function useApiKey(): [string, (value: string) => void] { | ||
const maybeKey = ApiKey.getApiKey(); | ||
const [key, setKey] = useState(maybeKey); | ||
useEffect(() => { | ||
const apiKey = ApiKey.getApiKey(); | ||
setKey(apiKey); | ||
}, []); | ||
|
||
const setApiKey = (value: string) => { | ||
ApiKey.setApiKey(value); | ||
setKey(value); | ||
}; | ||
|
||
return [key, setApiKey]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Cookies from "js-cookie"; | ||
export const getApiKey = () => Cookies.get("api_key") ?? ""; | ||
|
||
export const setApiKey = (value: string) => { | ||
Cookies.set("api_key", value); | ||
}; |