All files / auth applicationEntry.ts

100% Statements 33/33
100% Branches 18/18
100% Functions 5/5
100% Lines 33/33

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 31 32 33 3420x 1x 1x 1x 1x 1x 1x 1x 19x 19x 19x 9x 10x 19x 1x 1x 76x 76x 44x 29x 24x 52x 76x 1x 1x 15x 15x 15x 1x 1x 20x 20x 20x  
import {
  getOnboardingGuardDecision,
  type OnboardingQueryState,
} from "@/features/onboarding/onboardingState"
import { getSafeInternalPath, withReturnTo } from "./safeRedirect"
import { isProtectedAppPath } from "@workspace/shared/appRoutes"
 
export function applicationEntryPath(
  onboarding: OnboardingQueryState
): "/dashboard" | "/onboarding" {
  return getOnboardingGuardDecision(onboarding) === "allow-dashboard"
    ? "/dashboard"
    : "/onboarding"
}
 
export function getProductReturnPath(value: string | null): string | null {
  const safePath = getSafeInternalPath(value)
  return safePath &&
    isProtectedAppPath(new URL(safePath, "https://cleo.local").pathname) &&
    !new URL(safePath, "https://cleo.local").pathname.startsWith("/onboarding")
    ? safePath
    : null
}
 
export function signInPath(returnTo: string | null): string {
  const safePath = getSafeInternalPath(returnTo)
  return safePath ? withReturnTo("/sign-in", safePath) : "/sign-in"
}
 
export function onboardingPath(returnTo: string | null): string {
  const safePath = getProductReturnPath(returnTo)
  return safePath ? withReturnTo("/onboarding", safePath) : "/onboarding"
}