Skip to content

Commit 7b857f9

Browse files
authored
fix: TanStack Start friction log fixes for middleware and doctor checks (#77)
* fix: clarify TanStack Start middleware setup to prevent createRouter confusion The installer agent could confuse TanStack Router's createRouter() with TanStack Start's server middleware config, instructing users to add authkitMiddleware to router.tsx instead of start.ts. Added explicit warning in SKILL.md and improved doctor check remediation with the correct code pattern. * fix: doctor callback route check now searches both flat and nested routes in src/ and app/ Previously only checked flat routes in src/ and nested routes in app/, causing false CALLBACK_ROUTE_MISSING errors for TanStack Start projects using nested routes in src/ (e.g. src/routes/api/auth/callback.tsx).
1 parent 6830a9f commit 7b857f9

3 files changed

Lines changed: 47 additions & 8 deletions

File tree

skills/workos-authkit-tanstack-start/SKILL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ Default redirect URI: `http://localhost:3000/api/auth/callback`
8686

8787
**authkitMiddleware MUST be configured or auth will fail silently.**
8888

89+
**WARNING: Do NOT add middleware to `createRouter()` in `router.tsx` or `app.tsx`. That is TanStack Router (client-side only). Server middleware belongs in `start.ts` using `requestMiddleware`.**
90+
8991
Create or update `src/start.ts` (or `app/start.ts` for legacy):
9092

9193
```typescript

src/doctor/checks/auth-patterns.spec.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ describe('checkAuthPatterns', () => {
368368
expect(result.findings.find((f) => f.code === 'CALLBACK_ROUTE_MISSING')).toBeUndefined();
369369
});
370370

371-
it('no finding when callback route exists (TanStack Start flat)', async () => {
371+
it('no finding when callback route exists (TanStack Start flat in src/)', async () => {
372372
writeFixtureFile(
373373
testDir,
374374
'src/routes/auth.callback.tsx',
@@ -382,6 +382,36 @@ describe('checkAuthPatterns', () => {
382382
);
383383
expect(result.findings.find((f) => f.code === 'CALLBACK_ROUTE_MISSING')).toBeUndefined();
384384
});
385+
386+
it('no finding when callback route exists (TanStack Start nested in src/)', async () => {
387+
writeFixtureFile(
388+
testDir,
389+
'src/routes/api/auth/callback.tsx',
390+
'export const Route = createFileRoute("/api/auth/callback")',
391+
);
392+
const result = await checkAuthPatterns(
393+
makeOptions(testDir),
394+
makeFramework({ name: 'TanStack Start', version: '1.0.0', expectedCallbackPath: '/api/auth/callback' }),
395+
makeEnv(),
396+
makeSdk({ name: '@workos-inc/authkit-tanstack-start' }),
397+
);
398+
expect(result.findings.find((f) => f.code === 'CALLBACK_ROUTE_MISSING')).toBeUndefined();
399+
});
400+
401+
it('no finding when callback route exists (TanStack Start flat in app/)', async () => {
402+
writeFixtureFile(
403+
testDir,
404+
'app/routes/api.auth.callback.tsx',
405+
'export const Route = createFileRoute("/api/auth/callback")',
406+
);
407+
const result = await checkAuthPatterns(
408+
makeOptions(testDir),
409+
makeFramework({ name: 'TanStack Start', version: '1.0.0', expectedCallbackPath: '/api/auth/callback' }),
410+
makeEnv(),
411+
makeSdk({ name: '@workos-inc/authkit-tanstack-start' }),
412+
);
413+
expect(result.findings.find((f) => f.code === 'CALLBACK_ROUTE_MISSING')).toBeUndefined();
414+
});
385415
});
386416

387417
describe('API_KEY_LEAKED_TO_CLIENT', () => {
@@ -514,7 +544,7 @@ describe('checkAuthPatterns', () => {
514544

515545
describe('MISSING_AUTHKIT_MIDDLEWARE (TanStack Start)', () => {
516546
it('warning when start.ts lacks authkitMiddleware', async () => {
517-
writeFixtureFile(testDir, 'src/start.ts', 'export default defineStart({})');
547+
writeFixtureFile(testDir, 'src/start.ts', 'export default createStart({})');
518548
const result = await checkAuthPatterns(
519549
makeOptions(testDir),
520550
makeFramework({ name: 'TanStack Start', expectedCallbackPath: '/auth/callback' }),
@@ -529,8 +559,9 @@ describe('checkAuthPatterns', () => {
529559
testDir,
530560
'src/start.ts',
531561
`
562+
import { createStart } from "@tanstack/react-start";
532563
import { authkitMiddleware } from "@workos-inc/authkit-tanstack-start";
533-
export default defineStart({ middleware: [authkitMiddleware()] });
564+
export default createStart({ requestMiddleware: [authkitMiddleware()] });
534565
`,
535566
);
536567
const result = await checkAuthPatterns(

src/doctor/checks/auth-patterns.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,16 @@ function checkCallbackRouteMissing(ctx: CheckContext): AuthPatternFinding[] {
299299
possiblePaths.push(join(ctx.installDir, 'app', 'routes', nested + `.${ext}`));
300300
}
301301
} else if (ctx.framework.name === 'TanStack Start') {
302-
// Modern flat: src/routes/api.auth.callback.tsx Legacy nested: app/routes/api/auth/callback.tsx
302+
// Flat: routes/api.auth.callback.tsx Nested: routes/api/auth/callback.tsx
303+
// Both conventions work in both src/ and app/ directories
303304
const segments = callbackPath.replace(/^\//, '').split('/');
304305
const flat = segments.join('.');
305306
const nested = segments.join('/');
306-
for (const ext of ['tsx', 'jsx', 'ts', 'js']) {
307-
possiblePaths.push(join(ctx.installDir, 'src', 'routes', `${flat}.${ext}`));
308-
possiblePaths.push(join(ctx.installDir, 'app', 'routes', nested + `.${ext}`));
307+
for (const prefix of ['src', 'app']) {
308+
for (const ext of ['tsx', 'jsx', 'ts', 'js']) {
309+
possiblePaths.push(join(ctx.installDir, prefix, 'routes', `${flat}.${ext}`));
310+
possiblePaths.push(join(ctx.installDir, prefix, 'routes', nested + `.${ext}`));
311+
}
309312
}
310313
}
311314

@@ -423,7 +426,10 @@ function checkMissingAuthkitMiddleware(ctx: CheckContext): AuthPatternFinding[]
423426
severity: 'warning',
424427
message: 'start.ts does not reference authkitMiddleware — AuthKit session handling requires it',
425428
filePath: relative(ctx.installDir, startFile),
426-
remediation: 'Add authkitMiddleware to your start.ts server middleware configuration.',
429+
remediation:
430+
'Add authkitMiddleware to requestMiddleware in src/start.ts:\n' +
431+
' import { authkitMiddleware } from "@workos/authkit-tanstack-react-start";\n' +
432+
' export default createStart({ requestMiddleware: [authkitMiddleware()] });',
427433
},
428434
];
429435
}

0 commit comments

Comments
 (0)