Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Improve auth layout; Fix redirects and sign up links

Tomas Valenta1c9c0d2805f2
diff --git a/apps/docs/src/app/getting-started/api-key/APIKey.tsx b/apps/docs/src/app/getting-started/api-key/APIKey.tsx
index 636f0f360..9417fa1cb 100644
--- a/apps/docs/src/app/getting-started/api-key/APIKey.tsx
+++ b/apps/docs/src/app/getting-started/api-key/APIKey.tsx
@@ -117,7 +117,7 @@ function APIKey() {
) : (
<div className="flex flex-col items-start justiy-start gap-4 mt-6">
<span>You can get your API key by signing up.</span>
- <Button onClick={() => signIn({ hash: 'auth-sign-up' })}>Sign up to get your API key</Button>
+ <Button onClick={() => signIn({ view: 'sign-up' })}>Sign up to get your API key</Button>
</div>
)}
</div>
diff --git a/apps/docs/src/app/sign/page.tsx b/apps/docs/src/app/sign-in/page.tsx
similarity index 100%
rename from apps/docs/src/app/sign/page.tsx
rename to apps/docs/src/app/sign-in/page.tsx
diff --git a/apps/docs/src/components/Auth.tsx b/apps/docs/src/components/Auth.tsx
index f2f61aaa9..13faf037c 100644
--- a/apps/docs/src/components/Auth.tsx
+++ b/apps/docs/src/components/Auth.tsx
@@ -4,7 +4,6 @@ import clsx from 'clsx'
import { LogOutIcon } from 'lucide-react'
import { useRouter } from 'next/navigation'
-
import { Button } from '@/components/Button'
import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'
import { useApiKey, useUser } from '@/utils/useUser'
@@ -14,7 +13,6 @@ import { usePostHog } from 'posthog-js/react'
import { obfuscateSecret } from '@/utils/obfuscate'
import { useSignIn } from '@/utils/useSignIn'
-
function CopyableSecret({
secret = '',
onAfterCopy,
@@ -117,7 +115,7 @@ export const Auth = function () {
<div className="flex items-center justify-center gap-3">
{/* @ts-ignore */}
<Button
- onClick={() => signIn({ hash: 'auth-sign-up' })}
+ onClick={() => signIn({ view: 'sign-up' })}
variant="textTernary"
className="whitespace-nowrap text-xs"
>
diff --git a/apps/docs/src/components/AuthForm.tsx b/apps/docs/src/components/AuthForm.tsx
index d544ad369..056c1d133 100644
--- a/apps/docs/src/components/AuthForm.tsx
+++ b/apps/docs/src/components/AuthForm.tsx
@@ -3,32 +3,96 @@
import { Auth } from '@supabase/auth-ui-react'
import {
ThemeSupa,
-
+ ViewType,
} from '@supabase/auth-ui-shared'
import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'
-import { useSearchParams } from 'next/navigation'
+import { useSearchParams, useRouter } from 'next/navigation'
+import { useEffect, useState } from 'react'
+import { Button } from '@/components/Button'
+import { useUser } from '@/utils/useUser'
const supabase = createClientComponentClient()
+function getView(hash: string): ViewType {
+ switch (hash) {
+ case 'sign-in':
+ return 'sign_in'
+ case 'sign-up':
+ return 'sign_up'
+ case 'forgotten-password':
+ return 'forgotten_password'
+ default:
+ return 'sign_in'
+ }
+}
+
function AuthForm() {
const searchParams = useSearchParams()
const redirectTo = searchParams.get('redirect_to')
+ const paramView = searchParams.get('view')
+ const router = useRouter()
+
+ const [view, setView] = useState<ViewType>(getView(paramView))
+
+ const user = useUser()
+
+ useEffect(function redirect() {
+ if (user.user) {
+ router.push(redirectTo)
+ }
+ }, [user.user, router, redirectTo])
+
return (
- <div className="flex flex-1 items-center">
- <Auth
- supabaseClient={supabase}
- appearance={{
- theme: ThemeSupa,
- }}
- theme="dark"
- providers={['github']}
- providerScopes={{
- github: 'email',
- }}
- redirectTo={redirectTo}
- />
- </div>
+ <div className="flex flex-1 justify-center items-center flex-col">
+ <span className="text-3xl pb-2">
+ {view === 'sign_in' && 'Sign in to E2B'}
+ {view === 'sign_up' && 'Sign up to E2B'}
+ {view === 'forgotten_password' && 'Reset password'}
+ </span>
+ <div className="flex">
+ <Auth
+ supabaseClient={supabase}
+ appearance={{
+ theme: ThemeSupa,
+ // TODO: Customize auth styling
+ // https://supabase.com/docs/guides/auth/auth-helpers/auth-ui#create-theme
+ // https://supabase.com/docs/guides/auth/auth-helpers/auth-ui#override-themes
+ }}
+ view={view}
+ theme="dark"
+ showLinks={false}
+ providers={['github']}
+ providerScopes={{
+ github: 'email',
+ }}
+ redirectTo={redirectTo}
+ />
+ </div>
+ <div className="flex flex-1 flex-col space-x-2">
+ {view !== 'sign_in' && <Button
+ onClick={() => setView('sign_in')}
+ variant="textSubtle"
+ >
+ Already have an account? Sign in
+ </Button>
+ }
+ {view === 'sign_in' && <Button
+ onClick={() => setView('forgotten_password')}
+ variant="textSubtle"
+ >
+ Forgot your password?
+ </Button>
+ }
+ {view === 'sign_in' && <Button
+ onClick={() => setView('sign_up')}
+ variant="textSubtle"
+ >
+ {'Don\'t have an account? Sign up'}
+ </Button>
+ }
+ </div>
+ </div >
)
}
diff --git a/apps/docs/src/components/ButtonLoginToken.tsx b/apps/docs/src/components/ButtonLoginToken.tsx
index d95c17888..95cdcc81b 100644
--- a/apps/docs/src/components/ButtonLoginToken.tsx
+++ b/apps/docs/src/components/ButtonLoginToken.tsx
@@ -14,7 +14,7 @@ export function ButtonLoginToken() {
return (
<Button
- onClick={() => signIn({ hash: 'auth-sign-up' })}
+ onClick={() => signIn({ view: 'sign-up' })}
variant="textTernary"
className={extraClassName}
>
diff --git a/apps/docs/src/components/Header.tsx b/apps/docs/src/components/Header.tsx
index 1e99ed25b..5d44d8fbe 100644
--- a/apps/docs/src/components/Header.tsx
+++ b/apps/docs/src/components/Header.tsx
@@ -21,7 +21,7 @@ const TopLevelNavItem = dynamic(() => import('@/components/TopLevelNavItem'), {
})
// @ts-ignore
-export const Header = forwardRef(function Header({ className }, ref) {
+export const Header = forwardRef(function Header({ className, isAuth }, ref) {
const { isOpen: mobileNavIsOpen } = useMobileNavigationStore()
const isInsideMobileNavigation = useIsInsideMobileNavigation()
@@ -91,7 +91,7 @@ export const Header = forwardRef(function Header({ className }, ref) {
<Logo className="h-6" />
</Link>
</div>
- <Search />
+ {!isAuth && <Search />}
<div className="flex items-center gap-5 lg:hidden">
<MobileNavigation />
<Link
@@ -101,7 +101,7 @@ export const Header = forwardRef(function Header({ className }, ref) {
<Logo className="h-6" />
</Link>
</div>
- <div className="flex items-center gap-4">
+ {!isAuth && <div className="flex items-center gap-4">
<nav className="hidden md:block">
<ul
role="list"
@@ -131,6 +131,7 @@ export const Header = forwardRef(function Header({ className }, ref) {
<Auth />
</div>
</div>
+ }
</motion.div>
)
})
diff --git a/apps/docs/src/components/Layout.tsx b/apps/docs/src/components/Layout.tsx
index dd40665d5..7438ff671 100644
--- a/apps/docs/src/components/Layout.tsx
+++ b/apps/docs/src/components/Layout.tsx
@@ -22,10 +22,11 @@ export function Layout({
const pathname = usePathname()
const relativePathname = pathname.replace(new RegExp('^/docs'), '')
const shouldShowBanner = user?.pricingTier.isPromo
+ const isAuth = relativePathname.startsWith('/sign-in')
return (
<SectionProvider sections={allSections[relativePathname] ?? []}>
- <div className="h-full lg:ml-[var(--sidebar-nav-width)]">
+ <div className={clsx('h-full', { 'lg:ml-[var(--sidebar-nav-width)]': !isAuth })}>
<motion.header
layoutScroll
className={clsx(
@@ -47,13 +48,15 @@ export function Layout({
lg:pb-8
"
>
- <Header />
- <Navigation className="hidden lg:my-4 lg:block" />
+ {/* @ts-ignore */}
+ <Header isAuth={isAuth} />
+ {!isAuth && <Navigation className="hidden lg:my-4 lg:block" />}
</div>
</motion.header>
{shouldShowBanner && <Banner />}
- <div
- className="
+ {!isAuth && (
+ <div
+ className="
relative
flex
h-full
@@ -67,13 +70,33 @@ export function Layout({
lg:px-8
lg:dark:border-white/10
"
- >
- <main className="
+ >
+ <main className="
flex-auto
">
- {children}</main>
- <Footer />
- </div>
+ {children}</main>
+ <Footer />
+ </div>
+ )}
+ {isAuth && (
+ <div
+ className="
+ relative
+ flex
+ h-full
+ flex-col
+ pt-14
+ "
+ >
+ <main className="
+ flex
+ flex-1
+ ">
+ {children}
+ </main>
+ <Footer />
+ </div>
+ )}
</div>
</SectionProvider>
)
diff --git a/apps/docs/src/utils/useSignIn.tsx b/apps/docs/src/utils/useSignIn.tsx
index e6891c229..d943c0d8c 100644
--- a/apps/docs/src/utils/useSignIn.tsx
+++ b/apps/docs/src/utils/useSignIn.tsx
@@ -3,7 +3,7 @@
import { useRouter } from 'next/navigation'
export interface Opts {
- hash?: string;
+ view?: string;
/**
* Redirect to the current URL after signing in
* @default Enabled by default
@@ -15,15 +15,23 @@ export function useSignIn() {
const router = useRouter()
return function signIn(opts?: Opts) {
- let target = '/sign'
+ let target = '/sign-in'
+
+ if (opts?.redirectToCurrentUrl !== false || opts?.view) {
+ target += '?'
+ }
if (opts?.redirectToCurrentUrl !== false) {
const url = typeof window !== 'undefined' ? window.location.href : undefined
- target += '?redirect_to=' + url
+ target += 'redirect_to=' + url
+ }
+
+ if (opts?.redirectToCurrentUrl !== false && opts?.view) {
+ target += '&'
}
- if (opts?.hash) {
- target += `#${opts.hash}`
+ if (opts?.view) {
+ target += 'view=' + opts.view
}
router.push(target, { scroll: true })