-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
117 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,124 @@ | ||
'use client' | ||
"use client"; | ||
|
||
import clsx from 'clsx' | ||
import { Button } from '@/components/Button' | ||
import { useApiKey, useUser } from '@/utils/useUser' | ||
import { obfuscateSecret } from '@/utils/obfuscate' | ||
import { CopyButton } from '@/components/CopyButton' | ||
import { usePostHog } from 'posthog-js/react' | ||
import { useSignIn } from '@/utils/useSignIn' | ||
import clsx from "clsx"; | ||
import { useAccessToken, useApiKey, useUser } from "@/utils/useUser"; | ||
import { usePostHog } from "posthog-js/react"; | ||
import { useSignIn } from "@/utils/useSignIn"; | ||
import { obfuscateSecret } from "@/utils/obfuscate"; | ||
import { Button } from "@/components/Button"; | ||
import { CopyButton } from "@/components/CopyButton"; | ||
import { Note } from '@/components/mdx' | ||
|
||
export function CopyableSecret({ | ||
secret, | ||
onAfterCopy, | ||
obfuscateStart, | ||
obfuscateEnd, | ||
}: { | ||
secret: string; | ||
onAfterCopy: () => void; | ||
obfuscateStart?: number; | ||
obfuscateEnd?: number; | ||
}) { | ||
return ( | ||
<div className="relative flex"> | ||
<span className="whitespace-nowrap font-mono text-yellow-400 group-hover:opacity-0"> | ||
{obfuscateSecret(secret, obfuscateStart, obfuscateEnd)} | ||
</span> | ||
<span className="absolute inset-0"> | ||
<CopyButton | ||
code={secret} | ||
onAfterCopy={onAfterCopy} | ||
customPositionClassNames={clsx( | ||
"top-[-2px] bottom-[2px]" /* nudge 2px up*/, | ||
"left-[-8px] right-[-8px]" /* widen a little to fit nicely */, | ||
"min-h-[28px]" | ||
)} | ||
/> | ||
</span> | ||
</div> | ||
); | ||
} | ||
|
||
function SecretBlock({ name, description, secret, posthog, tip }) { | ||
return ( | ||
<div className="flex flex-col space-y-1"> | ||
<h2 className="flex flex-row items-center justify-items-end align-text-bottom mt-6"> | ||
<span>{name}</span> | ||
<div className="group text-sm ml-4 border-2 mt-1 outline-2 outline-offset-2 outline-zinc-700 rounded-full px-[8px]"> | ||
<CopyableSecret | ||
secret={secret} | ||
onAfterCopy={() => posthog?.capture("copied API key")} | ||
obfuscateStart={12} | ||
obfuscateEnd={5} | ||
/> | ||
</div> | ||
</h2> | ||
<span>{description}</span> | ||
<span>{tip}</span> | ||
</div> | ||
); | ||
} | ||
function APIKey() { | ||
const signIn = useSignIn() | ||
const { user } = useUser() | ||
const apiKey = useApiKey() | ||
const posthog = usePostHog() | ||
const signIn = useSignIn(); | ||
const { user } = useUser(); | ||
const apiKey = useApiKey(); | ||
const posthog = usePostHog(); | ||
const accessToken = useAccessToken(); | ||
|
||
return ( | ||
<div className="flex flex-col items-start justify-start space-y-4"> | ||
<div className="flex flex-col items-start justify-start -mb-6"> | ||
{user ? ( | ||
<div | ||
className=" | ||
group relative flex | ||
flex-row | ||
gap-2 text-xs | ||
" | ||
> | ||
<span className="whitespace-nowrap font-bold text-zinc-400 group-hover:opacity-25"> | ||
API Key | ||
</span> | ||
<span className="whitespace-nowrap font-mono text-yellow-400 group-hover:opacity-25"> | ||
{obfuscateSecret(apiKey)} | ||
</span> | ||
<span className="absolute inset-0"> | ||
<CopyButton | ||
code={apiKey} | ||
onAfterCopy={() => posthog?.capture('copied API key')} | ||
customPositionClassNames={clsx( | ||
'top-[-2px] bottom-[2px]' /* nudge 2px up*/, | ||
'left-[-6px] right-[-6px]' /* widen a little to fit nicely */, | ||
'min-h-[28px]', | ||
)} | ||
/> | ||
</span> | ||
<div className="flex flex-col space-y-4"> | ||
<SecretBlock | ||
name="API Key" | ||
description={ | ||
<span> | ||
Use for <strong>running</strong> the sandboxes. | ||
</span> | ||
} | ||
secret={apiKey} | ||
posthog={posthog} | ||
tip={ | ||
<span> | ||
Set as <code>E2B_API_KEY</code> environment variable to avoid passing it | ||
every time. | ||
</span> | ||
} | ||
/> | ||
<SecretBlock | ||
name="Access Token" | ||
description={ | ||
<div className="flex flex-col"> | ||
<span> | ||
Use for <strong>managing</strong> the sandboxes | ||
(creating/listing/deleting). | ||
</span> | ||
<span> | ||
Not needed when logging in CLI via <code>e2b login</code>. | ||
</span> | ||
</div> | ||
} | ||
secret={accessToken} | ||
posthog={posthog} | ||
tip={ | ||
<Note> | ||
<div className="flex flex-col"> | ||
<span>To authenticate without the browser, you can set <code>E2B_ACCESS_TOKEN</code> as an environment variable.</span> | ||
<span>This can be useful for CI/CD pipelines.</span> | ||
</div> | ||
</Note> | ||
} | ||
/> | ||
</div> | ||
) : ( | ||
<> | ||
<div className="mt-6"> | ||
<span>You can get your API key by signing up.</span> | ||
<Button onClick={() => signIn()}>Sign up to get your API key</Button> | ||
</> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
); | ||
} | ||
|
||
export default APIKey | ||
export default APIKey; |
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
f70059d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
e2b-docs – ./apps/docs
e2b-docs.vercel.app
e2b-docs-e2b.vercel.app
e2b-docs-git-main-e2b.vercel.app