Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/web/src/actions/auth/sign-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ type SignInInput = {
redirectTo?: string
}

function getLocaleFromRedirectTo(redirectTo?: string) {
if (!redirectTo) return null

const locale = redirectTo.split('/').filter(Boolean)[0]
const isValidLocale = /^[a-z]{2}-[A-Z]{2}$/.test(locale ?? '')

return isValidLocale ? locale : null
}

export async function signIn({ login, password, redirectTo }: SignInInput) {
let token: string | undefined

Expand All @@ -37,7 +46,9 @@ export async function signIn({ login, password, redirectTo }: SignInInput) {

if (data?.user && !data.user.displayName) {
const cookieStore = await cookies()
const localeFromRedirect = getLocaleFromRedirectTo(redirectTo)
const lang =
localeFromRedirect ||
cookieStore.get('NEXT_LOCALE')?.value ||
cookieStore.get('i18next')?.value ||
'en-US'
Expand Down
6 changes: 0 additions & 6 deletions apps/web/src/app/[lang]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { headers } from 'next/headers'
import { Link } from 'next-view-transitions'
import type { GetUserPreferences200 } from '@/api/endpoints.schemas'
import { getUserPreferences } from '@/api/users'
Expand Down Expand Up @@ -43,10 +42,6 @@ export default async function RootLayout({
userPreferences = data?.userPreferences ?? null
}

const headersList = await headers()
const pathname = headersList.get('x-current-path') || ''
const isOnboarding = pathname.includes('/onboarding')

return (
<ThemeProvider
attribute="class"
Expand All @@ -63,7 +58,6 @@ export default async function RootLayout({
<LayoutWrapper
header={<Header />}
footer={<Footer dictionary={dictionary} language={lang} />}
isOnboarding={isOnboarding}
proBadge={
session?.user.subscriptionType !== 'PRO' ? (
<Link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function OnboardingCelebration({ lang }: { lang: string }) {
const subtitle =
dictionary?.celebration_subtitle ||
"Your profile is ready. Let's start tracking."
const cta = dictionary?.celebration_cta || 'Go to Home'
const cta = dictionary?.go_to_profile || 'Go to Profile'

return (
<div className="flex flex-1 h-full flex-col items-center justify-center px-6">
Expand Down
8 changes: 6 additions & 2 deletions apps/web/src/components/layout-wrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
'use client'

import { usePathname } from 'next/navigation'

export function LayoutWrapper({
header,
footer,
children,
proBadge,
isOnboarding,
}: {
header: React.ReactNode
footer: React.ReactNode
children: React.ReactNode
proBadge?: React.ReactNode
isOnboarding?: boolean
}) {
const pathname = usePathname()
const isOnboarding = pathname?.includes('/onboarding') ?? false

return (
<>
Expand Down
Loading