route.tsx 4.8 KB

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