All files / src/routes/_authed welcome.tsx

11.11% Statements 1/9
0% Branches 0/4
0% Functions 0/5
11.11% Lines 1/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30          1x                                                
import { createFileRoute, redirect, useRouter } from '@tanstack/react-router'
import { WelcomePage } from '#/features/authentication/WelcomePage'
import { safeRedirect } from '#/lib/redirect'
import { m } from '#/paraglide/messages.js'
 
export const Route = createFileRoute('/_authed/welcome')({
  validateSearch: (search): { redirect?: string } =>
    typeof search.redirect === 'string' ? { redirect: search.redirect } : {},
  // A user who has a name has nothing to do here.
  beforeLoad: ({ context }) => {
    if (context.user.name !== '') {
      throw redirect({ to: '/' })
    }
  },
  head: () => ({ meta: [{ title: m.welcome_page_title() }] }),
  component: WelcomeRoute,
})
 
function WelcomeRoute() {
  const router = useRouter()
  const { redirect: target } = Route.useSearch()
  return (
    <WelcomePage
      onSaved={() => {
        void router.navigate({ href: safeRedirect(target) })
      }}
    />
  )
}