mirror of
https://github.com/supabase/supabase.git
synced 2026-12-05 07:59:03 +00:00
feat(www): shared account menu (#53666)
## Problem - www keeps its own copy of the account menu items separate from the shared top nav menu in kb and docs - www header buttons stay hidden until auth loads and the mobile menu shows no account links during that time - on app router page such as the home page sign out does not reload the page ## Solution - moves the www desktop account menu onto the shared top nav menu so www docs and kb show the same account items - fixes "Command Menu" shortcut label to follow the platform, so windows and linux readers see "Ctrl K" - changes the header and the mobile menu to read the signed-in mark while auth loads - moves the mobile menu account links onto the shared mobile actions, so www, docs and kb use one component - changes the desktop "Sign in" links to open the sign-in page, so desktop and mobile open the same page - fixes sign out on app router pages so the page reloads after sign out on every page <!-- ## Preview links If relevant, include links to changed pages for easy review access. Copy the preview base URL from the Vercel bot comment on this PR. Use the following table as an example template. | Site | Live | Preview | Search for | | -------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------- | | WWW | [/blog/your-post](https://supabase.com/blog/your-post) | [/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post) | unique phrase from the change | | Docs | [/docs/guides/your-page](https://supabase.com/docs/guides/your-page) | [/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page) | unique phrase from the change | | Studio | [/dashboard](https://supabase.com/dashboard) | [/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard) | unique phrase from the change | | Design system | [/design-system](https://supabase.com/design-system) | [/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system) | unique phrase from the change | | UI library | [/library](https://supabase.com/library) | [/library](https://ui-library-git-branch-name-supabase.vercel.app/library) | unique phrase from the change | | Knowledge base | [/kb/guides/your-page](https://supabase.com/kb/guides/your-page) | [/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page) | unique phrase from the change | --> <!-- ## Additional context Optionally add any other context or screenshots. --> ## Review instructions 1. visit [homepage](https://zone-www-dot-com-git-antlio-fix-www-shared-account-menu-supabase.vercel.app/) 2. open the browser console, and run this snippet, which stores a fake dashboard session with no real token: ```js const user = { id: 'test', aud: 'authenticated', email: 'you@example.com', user_metadata: { avatar_url: 'https://github.com/supabase.png' } } const key = 'supabase.dashboard.auth.token' localStorage.setItem(key, JSON.stringify({ access_token: 'a.b.c', refresh_token: 'r', token_type: 'bearer', expires_in: 3600, expires_at: Math.floor(Date.now() / 1000) + 3600, user })) localStorage.setItem(`${key}-user`, JSON.stringify({ user }))``` 3. reload the page ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
This commit is contained in:
1 parent
c2292c97f2
commit
d885fc7458
8 files changed
+110
-136
No files matched your search
@@ -4,6 +4,7 @@ import '../styles/globals.css'
|
||||
import '../pages/launch-week/launchWeek.css'
|
||||
|
||||
import { inter, manrope, sourceCodePro } from '~/lib/fonts'
|
||||
import { SIGNED_IN_HINT_SCRIPT } from 'common/gotrue'
|
||||
import { genFaviconData } from 'common/MetaFavicons/app-router'
|
||||
import type { Metadata, Viewport } from 'next'
|
||||
|
||||
@@ -52,6 +53,9 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
||||
suppressHydrationWarning
|
||||
className={`${manrope.variable} ${inter.variable} ${sourceCodePro.variable}`}
|
||||
>
|
||||
<head>
|
||||
<script dangerouslySetInnerHTML={{ __html: SIGNED_IN_HINT_SCRIPT }} />
|
||||
</head>
|
||||
<body>
|
||||
<Providers>{children}</Providers>
|
||||
</body>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
'use client'
|
||||
|
||||
import { logOut, useUser } from 'common/auth'
|
||||
import { Command } from 'lucide-react'
|
||||
import { useTheme } from 'next-themes'
|
||||
import { DropdownMenuItem, DropdownMenuSeparator, DropdownMenuShortcut, KeyboardShortcut } from 'ui'
|
||||
import { useSetCommandMenuOpen } from 'ui-patterns/CommandMenu'
|
||||
import {
|
||||
TopNavAccountItems,
|
||||
TopNavDropdown,
|
||||
TopNavSignOutItem,
|
||||
TopNavThemeGroup,
|
||||
} from 'ui-patterns/TopNav/TopNavDropdown'
|
||||
|
||||
export const AccountMenu = () => {
|
||||
const user = useUser()
|
||||
const { theme, setTheme } = useTheme()
|
||||
const setCommandMenuOpen = useSetCommandMenuOpen()
|
||||
|
||||
const handleCommandMenuSelect = () => setCommandMenuOpen(true)
|
||||
|
||||
const handleSignOut = async () => {
|
||||
await logOut()
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
return (
|
||||
<TopNavDropdown>
|
||||
<TopNavAccountItems email={user?.email} />
|
||||
<DropdownMenuItem className="gap-2" onSelect={handleCommandMenuSelect}>
|
||||
<Command aria-hidden className="size-4 text-foreground-lighter" strokeWidth={1.5} />
|
||||
Command Menu
|
||||
<DropdownMenuShortcut>
|
||||
<KeyboardShortcut keys={['Meta', 'K']} variant="inline" />
|
||||
</DropdownMenuShortcut>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<TopNavThemeGroup value={theme} onValueChange={setTheme} />
|
||||
<DropdownMenuSeparator />
|
||||
<TopNavSignOutItem onSelect={handleSignOut} />
|
||||
</TopNavDropdown>
|
||||
)
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
'use client'
|
||||
|
||||
import { type Menu } from '~/data/nav'
|
||||
import { useIsLoggedIn, useIsUserLoading } from 'common'
|
||||
import { ChevronRight } from 'lucide-react'
|
||||
import Link from 'next/link'
|
||||
import { useState, type ComponentProps, type MouseEvent, type RefObject } from 'react'
|
||||
import { Button } from 'ui'
|
||||
import { MobileNavAccountActions } from 'ui-patterns/MobileNav/MobileNavAccountActions'
|
||||
import { MobileNavDrawer } from 'ui-patterns/MobileNav/MobileNavDrawer'
|
||||
import { MobileNavTabs } from 'ui-patterns/MobileNav/MobileNavTabs'
|
||||
import { SignedInSwitch } from 'ui-patterns/SignedInSwitch/SignedInSwitch'
|
||||
import { TextLink } from 'ui-patterns/TextLink'
|
||||
|
||||
import MenuItem from './MenuItem'
|
||||
@@ -25,8 +25,6 @@ interface MobileMenuProps {
|
||||
}
|
||||
|
||||
export const MobileMenu = ({ open, menu, toggleRef, onLinkClick, className }: MobileMenuProps) => {
|
||||
const isLoggedIn = useIsLoggedIn()
|
||||
const isUserLoading = useIsUserLoading()
|
||||
const sendTelemetryEvent = useSendTelemetryEvent()
|
||||
const [pickedTitle, setPickedTitle] = useState<string>(menu.primaryNav[0].title)
|
||||
const pickedItem = menu.primaryNav.find((menuItem) => menuItem.title === pickedTitle)
|
||||
@@ -36,6 +34,18 @@ export const MobileMenu = ({ open, menu, toggleRef, onLinkClick, className }: Mo
|
||||
if (event.target instanceof Element && event.target.closest('a')) onLinkClick()
|
||||
}
|
||||
|
||||
const handleSignInClick = () =>
|
||||
sendTelemetryEvent({
|
||||
action: 'sign_in_button_clicked',
|
||||
properties: { buttonLocation: 'Mobile Nav' },
|
||||
})
|
||||
|
||||
const handleSignUpClick = () =>
|
||||
sendTelemetryEvent({
|
||||
action: 'start_project_button_clicked',
|
||||
properties: { buttonLocation: 'Mobile Nav' },
|
||||
})
|
||||
|
||||
return (
|
||||
<MobileNavDrawer
|
||||
open={open}
|
||||
@@ -43,48 +53,16 @@ export const MobileMenu = ({ open, menu, toggleRef, onLinkClick, className }: Mo
|
||||
onClick={handleDrawerClick}
|
||||
className={className}
|
||||
footer={
|
||||
isUserLoading ? null : (
|
||||
<div className="flex items-stretch gap-4">
|
||||
{isLoggedIn ? (
|
||||
<Button block className="h-8 text-sm" asChild>
|
||||
<a type={undefined} href="/dashboard/projects">
|
||||
Dashboard
|
||||
</a>
|
||||
</Button>
|
||||
) : (
|
||||
<>
|
||||
<Button block className="h-8 text-sm" asChild>
|
||||
<a
|
||||
type={undefined}
|
||||
href="https://supabase.com/dashboard"
|
||||
onClick={() =>
|
||||
sendTelemetryEvent({
|
||||
action: 'sign_in_button_clicked',
|
||||
properties: { buttonLocation: 'Mobile Nav' },
|
||||
})
|
||||
}
|
||||
>
|
||||
Sign in
|
||||
</a>
|
||||
</Button>
|
||||
<Button variant="primary" block className="h-8 text-sm" asChild>
|
||||
<a
|
||||
type={undefined}
|
||||
href="https://supabase.com/dashboard/sign-up"
|
||||
onClick={() =>
|
||||
sendTelemetryEvent({
|
||||
action: 'start_project_button_clicked',
|
||||
properties: { buttonLocation: 'Mobile Nav' },
|
||||
})
|
||||
}
|
||||
>
|
||||
Start your project
|
||||
</a>
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
<SignedInSwitch
|
||||
signedIn={<MobileNavAccountActions isLoggedIn dashboardHref="/dashboard/projects" />}
|
||||
signedOut={
|
||||
<MobileNavAccountActions
|
||||
isLoggedIn={false}
|
||||
onSignInClick={handleSignInClick}
|
||||
onSignUpClick={handleSignUpClick}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<nav aria-label="Menu" className="flex flex-col gap-6">
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
'use client'
|
||||
|
||||
import { useIsLoggedIn, useIsUserLoading, useUser } from 'common'
|
||||
import ScrollProgress from 'components/ScrollProgress'
|
||||
import { getMenu } from 'data/nav'
|
||||
import { DevToolbarTrigger } from 'dev-tools'
|
||||
@@ -20,14 +19,15 @@ import {
|
||||
NavigationMenuTrigger,
|
||||
NavigationMenuViewport,
|
||||
} from 'ui'
|
||||
import { AuthenticatedDropdownMenu } from 'ui-patterns/AuthenticatedDropdownMenu'
|
||||
import { SignedInSwitch } from 'ui-patterns/SignedInSwitch/SignedInSwitch'
|
||||
import { TopNavMenuToggle } from 'ui-patterns/TopNav/TopNavMenuToggle'
|
||||
|
||||
import { AccountMenu } from './AccountMenu'
|
||||
import GitHubButton from './GitHubButton'
|
||||
import MenuItem from './MenuItem'
|
||||
import { MobileMenu } from './MobileMenu'
|
||||
import RightClickBrandLogo from './RightClickBrandLogo'
|
||||
import useDropdownMenu from './useDropdownMenu'
|
||||
import { DASHBOARD_SIGN_IN_URL, DASHBOARD_SIGN_UP_URL } from '@/lib/dashboard-links'
|
||||
|
||||
interface Props {
|
||||
hideNavbar: boolean
|
||||
@@ -50,9 +50,6 @@ const Nav = ({ hideNavbar, stickyNavbar = true }: Props) => {
|
||||
setVisibleDropdown(value)
|
||||
if (!openedDropdowns.includes(value)) setOpenedDropdowns([...openedDropdowns, value])
|
||||
}
|
||||
const isLoggedIn = useIsLoggedIn()
|
||||
const isUserLoading = useIsUserLoading()
|
||||
const user = useUser()
|
||||
const menu = getMenu()
|
||||
const dropdownTitles: string[] = menu.primaryNav
|
||||
.filter((menuItem) => menuItem.hasDropdown)
|
||||
@@ -62,7 +59,6 @@ const Nav = ({ hideNavbar, stickyNavbar = true }: Props) => {
|
||||
return dropdownTitles.indexOf(title) < dropdownTitles.indexOf(visibleDropdown) ? 'start' : 'end'
|
||||
}
|
||||
const sendTelemetryEvent = useSendTelemetryEvent()
|
||||
const userMenu = useDropdownMenu(user)
|
||||
|
||||
const isGAWeekSection = pathname?.startsWith('/ga-week')
|
||||
const isStateOfStartupsPage = pathname?.startsWith('/state-of-startups')
|
||||
@@ -194,15 +190,10 @@ const Nav = ({ hideNavbar, stickyNavbar = true }: Props) => {
|
||||
</NavigationMenu>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 opacity-0 animate-fade-in scale-100! delay-300">
|
||||
<div
|
||||
className={cn(
|
||||
'flex items-center gap-2 transition-opacity',
|
||||
isUserLoading ? 'opacity-0' : 'opacity-100'
|
||||
)}
|
||||
>
|
||||
<DevToolbarTrigger />
|
||||
<GitHubButton />
|
||||
{isLoggedIn ? (
|
||||
<DevToolbarTrigger />
|
||||
<GitHubButton />
|
||||
<SignedInSwitch
|
||||
signedIn={
|
||||
<>
|
||||
{isStateOfStartupsPage ? (
|
||||
<FloatingPlate rounded="md" className="hidden lg:inline-flex">
|
||||
@@ -215,15 +206,16 @@ const Nav = ({ hideNavbar, stickyNavbar = true }: Props) => {
|
||||
<a href="/dashboard/projects">Dashboard</a>
|
||||
</Button>
|
||||
)}
|
||||
<AuthenticatedDropdownMenu menu={userMenu} user={user} site="www" />
|
||||
<AccountMenu />
|
||||
</>
|
||||
) : (
|
||||
}
|
||||
signedOut={
|
||||
<>
|
||||
{isStateOfStartupsPage ? (
|
||||
<FloatingPlate rounded="md" className="hidden lg:inline-flex">
|
||||
<Button asChild>
|
||||
<a
|
||||
href="https://supabase.com/dashboard"
|
||||
href={DASHBOARD_SIGN_IN_URL}
|
||||
onClick={() =>
|
||||
sendTelemetryEvent({
|
||||
action: 'sign_in_button_clicked',
|
||||
@@ -238,7 +230,7 @@ const Nav = ({ hideNavbar, stickyNavbar = true }: Props) => {
|
||||
) : (
|
||||
<Button className="hidden lg:inline-flex" asChild>
|
||||
<a
|
||||
href="https://supabase.com/dashboard"
|
||||
href={DASHBOARD_SIGN_IN_URL}
|
||||
onClick={() =>
|
||||
sendTelemetryEvent({
|
||||
action: 'sign_in_button_clicked',
|
||||
@@ -252,7 +244,7 @@ const Nav = ({ hideNavbar, stickyNavbar = true }: Props) => {
|
||||
)}
|
||||
<Button variant="primary" className="hidden lg:inline-flex" asChild>
|
||||
<a
|
||||
href="https://supabase.com/dashboard/sign-up"
|
||||
href={DASHBOARD_SIGN_UP_URL}
|
||||
onClick={() =>
|
||||
sendTelemetryEvent({
|
||||
action: 'start_project_button_clicked',
|
||||
@@ -264,8 +256,8 @@ const Nav = ({ hideNavbar, stickyNavbar = true }: Props) => {
|
||||
</a>
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<TopNavMenuToggle
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import type { User } from '@supabase/supabase-js'
|
||||
import { logOut } from 'common'
|
||||
import { Command, Database, LogOut, Settings, UserIcon } from 'lucide-react'
|
||||
import { useRouter } from 'next/compat/router'
|
||||
import type { menuItem } from 'ui-patterns/AuthenticatedDropdownMenu'
|
||||
import { useSetCommandMenuOpen } from 'ui-patterns/CommandMenu'
|
||||
|
||||
const useDropdownMenu = (user: User | null) => {
|
||||
const router = useRouter()
|
||||
const setCommandMenuOpen = useSetCommandMenuOpen()
|
||||
|
||||
const menu: menuItem[][] = [
|
||||
[
|
||||
{
|
||||
label: user?.email ?? "You're logged in",
|
||||
type: 'text',
|
||||
icon: UserIcon,
|
||||
},
|
||||
{
|
||||
label: 'Account Preferences',
|
||||
icon: Settings,
|
||||
href: 'https://supabase.com/dashboard/account/me',
|
||||
},
|
||||
{
|
||||
label: 'All Projects',
|
||||
icon: Database,
|
||||
href: 'https://supabase.com/dashboard/projects',
|
||||
},
|
||||
{
|
||||
label: 'Command Menu',
|
||||
icon: Command,
|
||||
type: 'button',
|
||||
onClick: () => setCommandMenuOpen(true),
|
||||
shortcut: '⌘K',
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
label: 'Theme',
|
||||
type: 'theme',
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
label: 'Sign out',
|
||||
type: 'button',
|
||||
icon: LogOut,
|
||||
onClick: async () => {
|
||||
await logOut()
|
||||
router?.reload()
|
||||
},
|
||||
},
|
||||
],
|
||||
]
|
||||
|
||||
return menu
|
||||
}
|
||||
|
||||
export default useDropdownMenu
|
||||
@@ -1,6 +1,7 @@
|
||||
import { DASHBOARD_SIGN_UP_URL } from 'common/constants/dashboard-urls'
|
||||
|
||||
export { DASHBOARD_SIGN_IN_URL, DASHBOARD_SIGN_UP_URL } from 'common/constants/dashboard-urls'
|
||||
export const DASHBOARD_URL = 'https://supabase.com/dashboard'
|
||||
export const DASHBOARD_SIGN_IN_URL = 'https://supabase.com/dashboard/sign-in'
|
||||
export const DASHBOARD_SIGN_UP_URL = 'https://supabase.com/dashboard/sign-up'
|
||||
|
||||
/** Homepage/product "Start your project" CTA: sign-up for guests, dashboard for signed-in users. */
|
||||
export function getDashboardCtaHref(isLoggedIn: boolean): string {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { SIGNED_IN_HINT_SCRIPT } from 'common/gotrue'
|
||||
import Document, { Html, Head, Main, NextScript } from 'next/document'
|
||||
|
||||
export default class MyDocument extends Document {
|
||||
render() {
|
||||
return (
|
||||
<Html lang="en">
|
||||
<Head></Head>
|
||||
<Head>
|
||||
<script dangerouslySetInnerHTML={{ __html: SIGNED_IN_HINT_SCRIPT }} />
|
||||
</Head>
|
||||
<body>
|
||||
<Main />
|
||||
<NextScript />
|
||||
|
||||
@@ -7,6 +7,9 @@ import { buttonVariants, cn } from 'ui'
|
||||
|
||||
export interface MobileNavAccountActionsProps {
|
||||
isLoggedIn: boolean
|
||||
dashboardHref?: string
|
||||
onSignInClick?: () => void
|
||||
onSignUpClick?: () => void
|
||||
className?: string
|
||||
}
|
||||
|
||||
@@ -15,19 +18,30 @@ const accountLinkClassName = (variant: 'default' | 'primary') =>
|
||||
|
||||
export const MobileNavAccountActions = ({
|
||||
isLoggedIn,
|
||||
dashboardHref = DASHBOARD_PROJECTS_URL,
|
||||
onSignInClick,
|
||||
onSignUpClick,
|
||||
className,
|
||||
}: MobileNavAccountActionsProps) => (
|
||||
<div className={cn('flex items-stretch gap-4', className)}>
|
||||
{isLoggedIn ? (
|
||||
<a href={DASHBOARD_PROJECTS_URL} className={accountLinkClassName('default')}>
|
||||
<a href={dashboardHref} className={accountLinkClassName('default')}>
|
||||
Dashboard
|
||||
</a>
|
||||
) : (
|
||||
<>
|
||||
<a href={DASHBOARD_SIGN_IN_URL} className={accountLinkClassName('default')}>
|
||||
<a
|
||||
href={DASHBOARD_SIGN_IN_URL}
|
||||
onClick={onSignInClick}
|
||||
className={accountLinkClassName('default')}
|
||||
>
|
||||
Sign in
|
||||
</a>
|
||||
<a href={DASHBOARD_SIGN_UP_URL} className={accountLinkClassName('primary')}>
|
||||
<a
|
||||
href={DASHBOARD_SIGN_UP_URL}
|
||||
onClick={onSignUpClick}
|
||||
className={accountLinkClassName('primary')}
|
||||
>
|
||||
Start your project
|
||||
</a>
|
||||
</>
|
||||
|
||||
Reference in new issue
Block a user