-
Notifications
You must be signed in to change notification settings - Fork 286
[Feature] Support Auth Token #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2b9f9be
solve https://github.com/agno-agi/agent-ui/issues/124
complyue 93b27b5
fix format to pass validation
complyue 72116be
Apply suggestions from code review
Ayush0054 44be748
update
Ayush0054 5c7a1bf
update
Ayush0054 e76c7ae
cleanup
Ayush0054 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,146 @@ | ||
| 'use client' | ||
| import { Button } from '@/components/ui/button' | ||
| import { useStore } from '@/store' | ||
| import { motion, AnimatePresence } from 'framer-motion' | ||
| import { useState, useEffect } from 'react' | ||
| import Icon from '@/components/ui/icon' | ||
|
|
||
| const AuthToken = ({ | ||
| hasEnvToken, | ||
| envToken | ||
| }: { | ||
| hasEnvToken?: boolean | ||
| envToken?: string | ||
| }) => { | ||
| const { authToken, setAuthToken } = useStore() | ||
| const [isEditing, setIsEditing] = useState(false) | ||
| const [tokenValue, setTokenValue] = useState('') | ||
| const [isMounted, setIsMounted] = useState(false) | ||
| const [isHovering, setIsHovering] = useState(false) | ||
|
|
||
| useEffect(() => { | ||
| // Initialize with environment variable if available and no token is set | ||
| if (hasEnvToken && envToken && !authToken) { | ||
| setAuthToken(envToken) | ||
| setTokenValue(envToken) | ||
| } else { | ||
| setTokenValue(authToken) | ||
| } | ||
| setIsMounted(true) | ||
| }, [authToken, setAuthToken, hasEnvToken, envToken]) | ||
|
|
||
| const handleSave = () => { | ||
| const cleanToken = tokenValue.trim() | ||
| setAuthToken(cleanToken) | ||
| setIsEditing(false) | ||
| setIsHovering(false) | ||
| } | ||
|
|
||
| const handleCancel = () => { | ||
| setTokenValue(authToken) | ||
| setIsEditing(false) | ||
| setIsHovering(false) | ||
| } | ||
|
|
||
| const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
| if (e.key === 'Enter') { | ||
| handleSave() | ||
| } else if (e.key === 'Escape') { | ||
| handleCancel() | ||
| } | ||
| } | ||
|
|
||
| const handleClear = () => { | ||
| setAuthToken('') | ||
| setTokenValue('') | ||
| } | ||
|
|
||
| const displayValue = authToken | ||
| ? `${'*'.repeat(Math.min(authToken.length, 20))}${authToken.length > 20 ? '...' : ''}` | ||
| : 'NO TOKEN SET' | ||
|
|
||
| return ( | ||
| <div className="flex flex-col items-start gap-2"> | ||
| <div className="text-xs font-medium uppercase text-primary"> | ||
| Auth Token | ||
| </div> | ||
| {isEditing ? ( | ||
| <div className="flex w-full items-center gap-1"> | ||
| <input | ||
| type="password" | ||
| value={tokenValue} | ||
| onChange={(e) => setTokenValue(e.target.value)} | ||
| onKeyDown={handleKeyDown} | ||
| placeholder="Enter authentication token..." | ||
| className="flex h-9 w-full items-center text-ellipsis rounded-xl border border-primary/15 bg-accent p-3 text-xs font-medium text-muted placeholder:text-muted/50" | ||
| autoFocus | ||
| /> | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| onClick={handleSave} | ||
| className="hover:cursor-pointer hover:bg-transparent" | ||
| > | ||
| <Icon type="save" size="xs" /> | ||
| </Button> | ||
| </div> | ||
| ) : ( | ||
| <div className="flex w-full items-center gap-1"> | ||
| <motion.div | ||
| className="relative flex h-9 w-full cursor-pointer items-center justify-between rounded-xl border border-primary/15 bg-accent p-3 uppercase" | ||
| onMouseEnter={() => setIsHovering(true)} | ||
| onMouseLeave={() => setIsHovering(false)} | ||
| onClick={() => setIsEditing(true)} | ||
| transition={{ type: 'spring', stiffness: 400, damping: 10 }} | ||
| > | ||
| <AnimatePresence mode="wait"> | ||
| {isHovering ? ( | ||
| <motion.div | ||
| key="token-display-hover" | ||
| className="absolute inset-0 flex items-center justify-center" | ||
| initial={{ opacity: 0 }} | ||
| animate={{ opacity: 1 }} | ||
| exit={{ opacity: 0 }} | ||
| transition={{ duration: 0.2 }} | ||
| > | ||
| <p className="flex items-center gap-2 whitespace-nowrap text-xs font-medium text-primary"> | ||
| <Icon type="edit" size="xxs" /> EDIT TOKEN | ||
| </p> | ||
| </motion.div> | ||
| ) : ( | ||
| <motion.div | ||
| key="token-display" | ||
| className="absolute inset-0 flex items-center justify-between px-3" | ||
| initial={{ opacity: 0 }} | ||
| animate={{ opacity: 1 }} | ||
| exit={{ opacity: 0 }} | ||
| transition={{ duration: 0.2 }} | ||
| > | ||
| <p className="text-xs font-medium text-muted"> | ||
| {isMounted ? displayValue : 'NO TOKEN SET'} | ||
| </p> | ||
| {authToken && ( | ||
| <div className="size-2 shrink-0 rounded-full bg-positive" /> | ||
| )} | ||
| </motion.div> | ||
| )} | ||
| </AnimatePresence> | ||
| </motion.div> | ||
| {authToken && ( | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| onClick={handleClear} | ||
| className="hover:cursor-pointer hover:bg-transparent" | ||
| title="Clear token" | ||
| > | ||
| <Icon type="x" size="xs" /> | ||
| </Button> | ||
| )} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default AuthToken |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.