Skip to content

Commit 4792ace

Browse files
amikofalvydimaMachina
authored andcommitted
Revert "fix: add server-side auth gate to tenant layout (#1976)" (#1980)
This reverts commit a9f06e4.
1 parent e1c89dd commit 4792ace

File tree

4 files changed

+19
-43
lines changed

4 files changed

+19
-43
lines changed

agents-manage-ui/src/app/[tenantId]/layout.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
import { cookies } from 'next/headers';
2-
import { redirect } from 'next/navigation';
1+
import type { FC } from 'react';
32
import { HeaderMenus } from '@/components/layout/header-menus';
43
import { SentryScopeProvider } from '@/components/sentry-scope-provider';
54
import { AppSidebarProvider } from '@/components/sidebar-nav/app-sidebar-provider';
65
import { Separator } from '@/components/ui/separator';
76
import { SidebarInset, SidebarTrigger } from '@/components/ui/sidebar';
8-
import { BETTER_AUTH_SESSION_TOKEN_COOKIE } from '@/lib/auth/constants';
97
import { cn } from '@/lib/utils';
108

11-
export default async function Layout({ children, breadcrumbs }: LayoutProps<'/[tenantId]'>) {
12-
// Server-side auth gate: redirect to login if no session cookie is present.
13-
// This protects all routes under /[tenantId]/* (work-apps, stats, settings, etc.)
14-
// from being rendered without authentication.
15-
const cookieStore = await cookies();
16-
const sessionToken = cookieStore.get(BETTER_AUTH_SESSION_TOKEN_COOKIE);
17-
18-
if (!sessionToken?.value) {
19-
redirect('/login');
20-
}
21-
9+
const Layout: FC<LayoutProps<'/[tenantId]'>> = ({ children, breadcrumbs }) => {
2210
return (
2311
<AppSidebarProvider>
2412
<SentryScopeProvider>
@@ -55,4 +43,6 @@ export default async function Layout({ children, breadcrumbs }: LayoutProps<'/[t
5543
</SentryScopeProvider>
5644
</AppSidebarProvider>
5745
);
58-
}
46+
};
47+
48+
export default Layout;

agents-manage-ui/src/app/logout/route.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import { cookies } from 'next/headers';
22
import { type NextRequest, NextResponse } from 'next/server';
33
import { getAgentsApiUrl } from '@/lib/api/api-config';
4-
import { BETTER_AUTH_COOKIE_PREFIX, BETTER_AUTH_COOKIES } from '@/lib/auth/constants';
54
import { getLogger } from '@/lib/logger';
65

6+
/**
7+
* Known better-auth cookie names to clear.
8+
* These follow the pattern: better-auth.{cookie_name}
9+
*/
10+
const BETTER_AUTH_COOKIES = [
11+
'better-auth.session_token',
12+
'better-auth.session_data',
13+
'better-auth.dont_remember',
14+
'better-auth.two_factor',
15+
];
16+
717
const DEFAULT_REDIRECT = '/login';
818

919
/**
@@ -39,7 +49,7 @@ export async function GET(request: NextRequest) {
3949

4050
// Get all better-auth cookies to forward to the sign-out endpoint
4151
const allCookies = cookieStore.getAll();
42-
const authCookies = allCookies.filter((c) => c.name.includes(BETTER_AUTH_COOKIE_PREFIX));
52+
const authCookies = allCookies.filter((c) => c.name.includes('better-auth'));
4353
const cookieHeader = authCookies.map((c) => `${c.name}=${c.value}`).join('; ');
4454

4555
// Call the better-auth sign-out endpoint on the agents API

agents-manage-ui/src/lib/api/api-config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* Centralized configuration for API endpoints and settings
55
*/
66

7-
import { BETTER_AUTH_COOKIE_PREFIX } from '../auth/constants';
87
import { DEFAULT_INKEEP_AGENTS_API_URL } from '../runtime-config/defaults';
98
import { ApiError } from '../types/errors';
109

@@ -44,7 +43,7 @@ async function makeApiRequestInternal<T>(
4443
if (rawCookieHeader) {
4544
// Filter to only forward Better Auth cookies for security
4645
const cookiePairs = rawCookieHeader.split(';').map((c) => c.trim());
47-
const authCookies = cookiePairs.filter((c) => c.includes(BETTER_AUTH_COOKIE_PREFIX));
46+
const authCookies = cookiePairs.filter((c) => c.includes('better-auth'));
4847
cookieHeader = authCookies.join('; ');
4948
}
5049

@@ -53,7 +52,7 @@ async function makeApiRequestInternal<T>(
5352
const { cookies } = await import('next/headers');
5453
const cookieStore = await cookies();
5554
const allCookies = cookieStore.getAll();
56-
const authCookies = allCookies.filter((c) => c.name.includes(BETTER_AUTH_COOKIE_PREFIX));
55+
const authCookies = allCookies.filter((c) => c.name.includes('better-auth'));
5756
cookieHeader = authCookies.map((c) => `${c.name}=${c.value}`).join('; ');
5857
}
5958
} catch {

agents-manage-ui/src/lib/auth/constants.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)