Skip to content

Commit 59bf3b6

Browse files
wobsorianonikosdouvlis
authored andcommitted
chore(react-router): Remove deprecated pre-middleware setup (#7796)
1 parent f471a10 commit 59bf3b6

9 files changed

Lines changed: 54 additions & 498 deletions

File tree

.changeset/green-humans-yawn.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
'@clerk/react-router': major
3+
---
4+
5+
Usage of `rootAuthLoader` without the `clerkMiddleware()` installed will not throw a runtime error.
6+
7+
**Before (Removed):**
8+
9+
```tsx
10+
import { rootAuthLoader } from '@clerk/react-router/ssr.server'
11+
12+
export const loader = (args: Route.LoaderArgs) => rootAuthLoader(args)
13+
```
14+
15+
**After:**
16+
17+
1. Enable the `v8_middleware` future flag:
18+
19+
```ts
20+
// react-router.config.ts
21+
export default {
22+
future: {
23+
v8_middleware: true,
24+
},
25+
} satisfies Config;
26+
```
27+
28+
2. Use the middleware in your app:
29+
30+
```tsx
31+
import { clerkMiddleware, rootAuthLoader } from '@clerk/react-router/server'
32+
33+
export const middleware: Route.MiddlewareFunction[] = [clerkMiddleware()]
34+
35+
export const loader = (args: Route.LoaderArgs) => rootAuthLoader(args)
36+
```

integration/tests/react-router/pre-middleware.test.ts

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

packages/react-router/src/server/__tests__/getAuth.test.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,14 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
44

55
import { authFnContext } from '../clerkMiddleware';
66
import { getAuth } from '../getAuth';
7-
import { legacyAuthenticateRequest } from '../legacyAuthenticateRequest';
8-
9-
vi.mock('../legacyAuthenticateRequest', () => {
10-
return {
11-
legacyAuthenticateRequest: vi.fn().mockResolvedValue({
12-
toAuth: vi.fn().mockImplementation(() => ({
13-
userId: 'user_xxx',
14-
tokenType: TokenType.SessionToken,
15-
})),
16-
headers: new Headers(),
17-
status: 'signed-in',
18-
}),
19-
};
20-
});
217

228
describe('getAuth', () => {
239
beforeEach(() => {
2410
vi.clearAllMocks();
2511
process.env.CLERK_SECRET_KEY = 'sk_test_...';
2612
});
2713

28-
it('should not call legacyAuthenticateRequest when middleware context exists', async () => {
14+
it('should work when middleware context exists', async () => {
2915
const mockContext = {
3016
get: vi.fn().mockImplementation(contextKey => {
3117
if (contextKey === authFnContext) {
@@ -47,12 +33,11 @@ describe('getAuth', () => {
4733

4834
const auth = await getAuth(args);
4935

50-
expect(legacyAuthenticateRequest).not.toHaveBeenCalled();
5136
expect(auth.userId).toBe('user_xxx');
5237
expect(auth.tokenType).toBe('session_token');
5338
});
5439

55-
it('should call legacyAuthenticateRequest when middleware context is missing', async () => {
40+
it('should throw an error when middleware context is missing', async () => {
5641
const mockContext = {
5742
get: vi.fn().mockReturnValue(null),
5843
};
@@ -62,10 +47,6 @@ describe('getAuth', () => {
6247
request: new Request('http://clerk.com'),
6348
} as LoaderFunctionArgs;
6449

65-
const auth = await getAuth(args);
66-
67-
expect(legacyAuthenticateRequest).toHaveBeenCalled();
68-
expect(auth.userId).toBe('user_xxx');
69-
expect(auth.tokenType).toBe('session_token');
50+
await expect(getAuth(args)).rejects.toThrow('Clerk: clerkMiddleware() not detected');
7051
});
7152
});

0 commit comments

Comments
 (0)