Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(profile-ui): prevent signed-in invite link crashes

Josué84bb1126ef45
diff --git a/profile-ui/app/components/ProfileAppFrame/index.tsx b/profile-ui/app/components/ProfileAppFrame/index.tsx
index 502d30d40..e952f7d1a 100644
--- a/profile-ui/app/components/ProfileAppFrame/index.tsx
+++ b/profile-ui/app/components/ProfileAppFrame/index.tsx
@@ -1,17 +1,28 @@
'use client'
import type { ReactNode } from 'react'
-import { usePathname, useSearchParams } from 'next/navigation'
+import { useEffect } from 'react'
+import { usePathname, useRouter, useSearchParams } from 'next/navigation'
import { AuthGate } from '@components/AuthGate'
import { ProfileAccessProvider } from '@components/ProfileAccessContext'
import { ProfileShell } from '@components/ProfileShell'
-import { isPublicProfileUiRequest } from '@lib/profileAppFrame'
+import { PROFILE_ROUTES } from '@constants/routes'
+import { getRootInviteToken, isPublicProfileUiPath } from '@lib/profileAppFrame'
export function ProfileAppFrame({ children }: { children: ReactNode }) {
+ const router = useRouter()
const pathname = usePathname()
const searchParams = useSearchParams()
+ const rootInviteToken = getRootInviteToken(pathname, searchParams)
- if (isPublicProfileUiRequest(pathname, searchParams)) {
+ useEffect(() => {
+ if (!rootInviteToken) return
+ router.replace(PROFILE_ROUTES.invitation(rootInviteToken))
+ }, [rootInviteToken, router])
+
+ if (rootInviteToken) return null
+
+ if (isPublicProfileUiPath(pathname)) {
return <>{children}</>
}
diff --git a/profile-ui/app/components/__tests__/ProfileAppFrame.invite.test.tsx b/profile-ui/app/components/__tests__/ProfileAppFrame.invite.test.tsx
new file mode 100644
index 000000000..0571e7743
--- /dev/null
+++ b/profile-ui/app/components/__tests__/ProfileAppFrame.invite.test.tsx
@@ -0,0 +1,143 @@
+import React from 'react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import '@testing-library/jest-dom/vitest'
+import { cleanup, render, screen, waitFor } from '@testing-library/react'
+import { ProfileAppFrame } from '@components/ProfileAppFrame'
+import Page from '../../page'
+
+const navigationState = vi.hoisted(() => ({
+ pathname: '/',
+ search: '',
+ replace: vi.fn(),
+}))
+
+const authState = vi.hoisted(() => ({
+ isLoggedIn: true,
+ isLoading: false,
+ me: {
+ id: 'user-1',
+ email: '[email protected]',
+ name: 'Ada Admin',
+ role: 'admin',
+ profile: {
+ displayName: 'Ada Admin',
+ },
+ },
+}))
+
+vi.mock('next/navigation', () => ({
+ usePathname: () => navigationState.pathname,
+ useRouter: () => ({ replace: navigationState.replace }),
+ useSearchParams: () => new URLSearchParams(navigationState.search),
+}))
+
+vi.mock('next/image', () => ({
+ default: ({ alt = '', ...props }: React.ImgHTMLAttributes<HTMLImageElement>) => (
+ // eslint-disable-next-line @next/next/no-img-element
+ <img alt={alt} {...props} />
+ ),
+}))
+
+vi.mock('next/link', () => ({
+ default: ({
+ children,
+ href,
+ ...props
+ }: React.AnchorHTMLAttributes<HTMLAnchorElement> & { href: string }) => (
+ <a href={href} {...props}>
+ {children}
+ </a>
+ ),
+}))
+
+vi.mock('@components/AuthContext', () => ({
+ useAuth: () => ({
+ authState,
+ checkAuth: vi.fn(),
+ login: vi.fn(),
+ logout: vi.fn(),
+ }),
+}))
+
+vi.mock('@components/LoginPanel', () => ({
+ LoginPanel: () => <div data-testid="profile-login-panel">login-panel</div>,
+}))
+
+function renderRootPage() {
+ return render(
+ <ProfileAppFrame>
+ <Page />
+ </ProfileAppFrame>
+ )
+}
+
+beforeEach(() => {
+ navigationState.pathname = '/'
+ navigationState.search = ''
+ navigationState.replace.mockClear()
+ authState.isLoggedIn = true
+ authState.isLoading = false
+ authState.me = {
+ id: 'user-1',
+ email: '[email protected]',
+ name: 'Ada Admin',
+ role: 'admin',
+ profile: {
+ displayName: 'Ada Admin',
+ },
+ }
+})
+
+afterEach(cleanup)
+
+describe('ProfileAppFrame root invite redirects', () => {
+ it('redirects signed-in root invite links before rendering the home shell', async () => {
+ navigationState.search = 'inviteToken=abc'
+
+ renderRootPage()
+
+ await waitFor(() => {
+ expect(navigationState.replace).toHaveBeenCalledWith('/invitations/abc')
+ })
+ expect(screen.queryByText(/Welcome, Ada Admin/i)).not.toBeInTheDocument()
+ })
+
+ it('redirects logged-out root invite links before showing login', async () => {
+ navigationState.search = 'inviteToken=abc'
+ authState.isLoggedIn = false
+ authState.me = null
+
+ renderRootPage()
+
+ await waitFor(() => {
+ expect(navigationState.replace).toHaveBeenCalledWith('/invitations/abc')
+ })
+ expect(screen.queryByTestId('profile-login-panel')).not.toBeInTheDocument()
+ })
+
+ it('keeps ordinary signed-in root rendering inside a single profile shell', () => {
+ const view = renderRootPage()
+
+ expect(screen.getByRole('heading', { name: /Welcome, Ada Admin/i })).toBeInTheDocument()
+ expect(view.container.querySelectorAll('.cu-sidebar')).toHaveLength(1)
+ expect(navigationState.replace).not.toHaveBeenCalled()
+ })
+
+ it('keeps unrelated root query strings protected', () => {
+ navigationState.search = 'next=%2Fmembers'
+
+ renderRootPage()
+
+ expect(screen.getByRole('heading', { name: /Welcome, Ada Admin/i })).toBeInTheDocument()
+ expect(navigationState.replace).not.toHaveBeenCalled()
+ })
+
+ it('keeps empty invite tokens protected', () => {
+ navigationState.search = 'inviteToken='
+
+ renderRootPage()
+
+ expect(screen.getByRole('heading', { name: /Welcome, Ada Admin/i })).toBeInTheDocument()
+ expect(navigationState.replace).not.toHaveBeenCalled()
+ })
+})
diff --git a/profile-ui/app/page.tsx b/profile-ui/app/page.tsx
index 9468d4347..81c428aa7 100644
--- a/profile-ui/app/page.tsx
+++ b/profile-ui/app/page.tsx
@@ -1,24 +1,7 @@
'use client'
-import { Suspense, useEffect } from 'react'
-import { useRouter, useSearchParams } from 'next/navigation'
import { useAuth } from '@components/AuthContext'
import { AuthGate } from '@components/AuthGate'
-import { ProfileShell } from '@components/ProfileShell'
-import { PROFILE_ROUTES } from '@constants/routes'
-
-function InvitationRedirect() {
- const router = useRouter()
- const searchParams = useSearchParams()
-
- useEffect(() => {
- const inviteToken = searchParams.get('inviteToken')
- if (!inviteToken) return
- router.replace(PROFILE_ROUTES.invitation(inviteToken))
- }, [router, searchParams])
-
- return null
-}
function HomeContent() {
const { authState } = useAuth()
@@ -26,42 +9,35 @@ function HomeContent() {
const displayName = me?.profile?.displayName || me?.name || me?.email || 'there'
return (
- <ProfileShell currentRoute="home">
- <section className="cu-page-stack">
- <div className="cu-card">
- <div className="cu-card__body">
- <p className="eyebrow">Evenfire Profile</p>
- <h2 className="page-title page-title--large">Welcome, {displayName}</h2>
- <p className="body-copy">You are signed in to your Evenfire profile.</p>
- </div>
+ <section className="cu-page-stack">
+ <div className="cu-card">
+ <div className="cu-card__body">
+ <p className="eyebrow">Evenfire Profile</p>
+ <h2 className="page-title page-title--large">Welcome, {displayName}</h2>
+ <p className="body-copy">You are signed in to your Evenfire profile.</p>
</div>
+ </div>
- <div className="cu-card">
- <div className="cu-card__body cu-profile-summary">
- <div>
- <span className="form-field__label">User</span>
- <div>{displayName}</div>
- </div>
- <div>
- <span className="form-field__label">Email</span>
- <div>{me?.email}</div>
- </div>
+ <div className="cu-card">
+ <div className="cu-card__body cu-profile-summary">
+ <div>
+ <span className="form-field__label">User</span>
+ <div>{displayName}</div>
+ </div>
+ <div>
+ <span className="form-field__label">Email</span>
+ <div>{me?.email}</div>
</div>
</div>
- </section>
- </ProfileShell>
+ </div>
+ </section>
)
}
export default function Page() {
return (
- <>
- <Suspense fallback={null}>
- <InvitationRedirect />
- </Suspense>
- <AuthGate>
- <HomeContent />
- </AuthGate>
- </>
+ <AuthGate>
+ <HomeContent />
+ </AuthGate>
)
}
diff --git a/profile-ui/lib/profileAppFrame.ts b/profile-ui/lib/profileAppFrame.ts
index f7eb2fad1..20c18c474 100644
--- a/profile-ui/lib/profileAppFrame.ts
+++ b/profile-ui/lib/profileAppFrame.ts
@@ -6,10 +6,15 @@ export function isPublicProfileUiPath(pathname: string): boolean {
)
}
+export function getRootInviteToken(pathname: string, searchParams: URLSearchParams): string | null {
+ if (pathname !== '/') return null
+ const inviteToken = searchParams.get('inviteToken')
+ return inviteToken && inviteToken.length > 0 ? inviteToken : null
+}
+
export function isPublicProfileUiRequest(pathname: string, searchParams: URLSearchParams): boolean {
if (isPublicProfileUiPath(pathname)) return true
- const inviteToken = searchParams.get('inviteToken')
- return pathname === '/' && inviteToken !== null && inviteToken.length > 0
+ return getRootInviteToken(pathname, searchParams) !== null
}
export type ProfileRouteKey =
diff --git a/profile-ui/package-lock.json b/profile-ui/package-lock.json
index 32937e6b9..1eb798411 100644
--- a/profile-ui/package-lock.json
+++ b/profile-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.108",
+ "version": "0.1.109",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-profile-ui",
- "version": "0.1.108",
+ "version": "0.1.109",
"dependencies": {
"next": "16.2.11",
"react": "^18.3.1",
diff --git a/profile-ui/package.json b/profile-ui/package.json
index 2aee51694..f73652280 100644
--- a/profile-ui/package.json
+++ b/profile-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-profile-ui",
- "version": "0.1.108",
+ "version": "0.1.109",
"private": true,
"scripts": {
"dev": "next dev",