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
22 changes: 20 additions & 2 deletions rafts/frontend/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@
************************************************************************
*/

export default function RootPage() {
return null
import { NextIntlClientProvider } from 'next-intl'
import { getMessages } from 'next-intl/server'
import LandingChoice from '@/components/LandingPage/LandingChoice'
import AppLayout from '@/components/Layout/AppLayout'
import { auth } from '@/auth/cadc-auth/credentials'
import { isStaleSession } from '@/auth/cadc-auth/isStaleSession'

const RootPage = async () => {
const messages = await getMessages()
const session = await auth()

return (
<NextIntlClientProvider messages={messages}>
<AppLayout>
<LandingChoice session={isStaleSession(session) ? null : session} />
</AppLayout>
</NextIntlClientProvider>
)
}

export default RootPage
4 changes: 3 additions & 1 deletion rafts/frontend/src/components/User/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ const LoginForm = ({ authAction, returnUrl }: LoginFormProps) => {
// Handle successful login with a single redirect
if (result.success) {
// Use hard navigation to ensure server components refresh with new session
window.location.href = returnUrl
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ''
const url = returnUrl.startsWith(basePath) ? returnUrl : `${basePath}${returnUrl}`
window.location.href = url
}
} catch (error) {
console.error('Login error:', error)
Expand Down
1 change: 1 addition & 0 deletions rafts/frontend/src/i18n/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { createNavigation } from 'next-intl/navigation'
export const routing = defineRouting({
locales: ['en', 'fr'],
defaultLocale: 'en',
localePrefix: 'as-needed',
})

export const { Link, redirect, usePathname, useRouter, getPathname } = createNavigation(routing)
7 changes: 5 additions & 2 deletions rafts/frontend/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ const middleware = async (request: NextRequest) => {
// If not authenticated or session is stale (missing user name), redirect to login
const isStaleSession = session && (!session.user?.name || session.user.name.includes('undefined'))
if (!session || isStaleSession) {
const loginRequiredUrl = new URL('/login-required', request.url)
const loginRequiredUrl = request.nextUrl.clone()
loginRequiredUrl.pathname = '/login-required'
const returnPath = request.nextUrl.pathname || '/'
loginRequiredUrl.searchParams.set('returnUrl', returnPath)
return NextResponse.redirect(loginRequiredUrl)
Expand All @@ -150,7 +151,9 @@ const middleware = async (request: NextRequest) => {
const hasAccess = canAccessRoute(pathnameWithoutLocale, userRole)

if (!hasAccess) {
return NextResponse.redirect(new URL('/unauthorized', request.url))
const unauthorizedUrl = request.nextUrl.clone()
unauthorizedUrl.pathname = '/unauthorized'
return NextResponse.redirect(unauthorizedUrl)
}

// Continue with the locale-handled response
Expand Down