route.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* eslint-disable react-refresh/only-export-components */
  2. import { createFileRoute, Outlet } from '@tanstack/react-router'
  3. import { ClerkProvider } from '@clerk/react'
  4. import { ExternalLink, Key } from 'lucide-react'
  5. import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
  6. import { Separator } from '@/components/ui/separator'
  7. import { SidebarTrigger } from '@/components/ui/sidebar'
  8. import { ConfigDrawer } from '@/components/config-drawer'
  9. import { AuthenticatedLayout } from '@/components/layout/authenticated-layout'
  10. import { Main } from '@/components/layout/main'
  11. import { ThemeSwitch } from '@/components/theme-switch'
  12. export const Route = createFileRoute('/clerk')({
  13. component: RouteComponent,
  14. })
  15. // Import your Publishable Key
  16. const PUBLISHABLE_KEY = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY
  17. function RouteComponent() {
  18. if (!PUBLISHABLE_KEY) {
  19. return <MissingClerkPubKey />
  20. }
  21. return (
  22. <ClerkProvider
  23. publishableKey={PUBLISHABLE_KEY}
  24. afterSignOutUrl='/clerk/sign-in'
  25. signInUrl='/clerk/sign-in'
  26. signUpUrl='/clerk/sign-up'
  27. signInFallbackRedirectUrl='/clerk/user-management'
  28. signUpFallbackRedirectUrl='/clerk/user-management'
  29. >
  30. <Outlet />
  31. </ClerkProvider>
  32. )
  33. }
  34. function MissingClerkPubKey() {
  35. const codeBlock =
  36. 'bg-foreground/10 rounded-sm py-0.5 px-1 text-xs text-foreground font-bold'
  37. return (
  38. <AuthenticatedLayout>
  39. <div className='bg-backgroundh-16 flex justify-between p-4'>
  40. <SidebarTrigger variant='outline' className='scale-125 sm:scale-100' />
  41. <div className='space-x-4'>
  42. <ThemeSwitch />
  43. <ConfigDrawer />
  44. </div>
  45. </div>
  46. <Main className='flex flex-col items-center justify-start'>
  47. <div className='max-w-2xl'>
  48. <Alert>
  49. <Key className='size-4' />
  50. <AlertTitle>No Publishable Key Found!</AlertTitle>
  51. <AlertDescription>
  52. <p className='text-balance'>
  53. You need to generate a publishable key from Clerk and put it
  54. inside the <code className={codeBlock}>.env</code> file.
  55. </p>
  56. </AlertDescription>
  57. </Alert>
  58. <h1 className='mt-4 text-2xl font-bold'>Set your Clerk API key</h1>
  59. <div className='mt-4 flex flex-col gap-y-4 text-foreground/75'>
  60. <ol className='list-inside list-decimal space-y-1.5'>
  61. <li>
  62. In the{' '}
  63. <a
  64. href='https://go.clerk.com/GttUAaK'
  65. target='_blank'
  66. className='underline decoration-dashed underline-offset-4 hover:decoration-solid'
  67. >
  68. Clerk
  69. <sup>
  70. <ExternalLink className='inline-block size-4' />
  71. </sup>
  72. </a>{' '}
  73. Dashboard, navigate to the API keys page.
  74. </li>
  75. <li>
  76. In the <strong>Quick Copy</strong> section, copy your Clerk
  77. Publishable Key.
  78. </li>
  79. <li>
  80. Rename <code className={codeBlock}>.env.example</code> to{' '}
  81. <code className={codeBlock}>.env</code>
  82. </li>
  83. <li>
  84. Paste your key into your <code className={codeBlock}>.env</code>{' '}
  85. file.
  86. </li>
  87. </ol>
  88. <p>The final result should resemble the following:</p>
  89. <div className='@container space-y-2 rounded-md bg-slate-800 px-3 py-3 text-sm text-slate-200'>
  90. <span className='ps-1'>.env</span>
  91. <pre className='overflow-auto overscroll-x-contain rounded bg-slate-950 px-2 py-1 text-xs'>
  92. <code>
  93. <span className='before:text-slate-400 md:before:pe-2 md:before:content-["1."]'>
  94. VITE_CLERK_PUBLISHABLE_KEY=YOUR_PUBLISHABLE_KEY
  95. </span>
  96. </code>
  97. </pre>
  98. </div>
  99. </div>
  100. <Separator className='my-4 w-full' />
  101. <Alert>
  102. <AlertTitle>Clerk Integration is Optional</AlertTitle>
  103. <AlertDescription>
  104. <p className='text-balance'>
  105. The Clerk integration lives entirely inside{' '}
  106. <code className={codeBlock}>src/routes/clerk</code>. If you plan
  107. to use Clerk as your auth service, you might want to place{' '}
  108. <code className={codeBlock}>ClerkProvider</code> at the root
  109. route.
  110. </p>
  111. <p>
  112. However, if you don't plan to use Clerk, you can safely remove
  113. this directory and related dependency_{' '}
  114. <code className={codeBlock}>@clerk/react</code>.
  115. </p>
  116. <p className='mt-2 text-sm'>
  117. This setup is modular by design and won't affect the rest of the
  118. application.
  119. </p>
  120. </AlertDescription>
  121. </Alert>
  122. </div>
  123. </Main>
  124. </AuthenticatedLayout>
  125. )
  126. }