Skip to content
Open
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
2 changes: 2 additions & 0 deletions skills/workos-authkit-tanstack-start/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ Default redirect URI: `http://localhost:3000/api/auth/callback`

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

**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`.**

Create or update `src/start.ts` (or `app/start.ts` for legacy):

```typescript
Expand Down
37 changes: 34 additions & 3 deletions src/doctor/checks/auth-patterns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ describe('checkAuthPatterns', () => {
expect(result.findings.find((f) => f.code === 'CALLBACK_ROUTE_MISSING')).toBeUndefined();
});

it('no finding when callback route exists (TanStack Start flat)', async () => {
it('no finding when callback route exists (TanStack Start flat in src/)', async () => {
writeFixtureFile(
testDir,
'src/routes/auth.callback.tsx',
Expand All @@ -382,6 +382,36 @@ describe('checkAuthPatterns', () => {
);
expect(result.findings.find((f) => f.code === 'CALLBACK_ROUTE_MISSING')).toBeUndefined();
});

it('no finding when callback route exists (TanStack Start nested in src/)', async () => {
writeFixtureFile(
testDir,
'src/routes/api/auth/callback.tsx',
'export const Route = createFileRoute("/api/auth/callback")',
);
const result = await checkAuthPatterns(
makeOptions(testDir),
makeFramework({ name: 'TanStack Start', version: '1.0.0', expectedCallbackPath: '/api/auth/callback' }),
makeEnv(),
makeSdk({ name: '@workos-inc/authkit-tanstack-start' }),
);
expect(result.findings.find((f) => f.code === 'CALLBACK_ROUTE_MISSING')).toBeUndefined();
});

it('no finding when callback route exists (TanStack Start flat in app/)', async () => {
writeFixtureFile(
testDir,
'app/routes/api.auth.callback.tsx',
'export const Route = createFileRoute("/api/auth/callback")',
);
const result = await checkAuthPatterns(
makeOptions(testDir),
makeFramework({ name: 'TanStack Start', version: '1.0.0', expectedCallbackPath: '/api/auth/callback' }),
makeEnv(),
makeSdk({ name: '@workos-inc/authkit-tanstack-start' }),
);
expect(result.findings.find((f) => f.code === 'CALLBACK_ROUTE_MISSING')).toBeUndefined();
});
});

describe('API_KEY_LEAKED_TO_CLIENT', () => {
Expand Down Expand Up @@ -514,7 +544,7 @@ describe('checkAuthPatterns', () => {

describe('MISSING_AUTHKIT_MIDDLEWARE (TanStack Start)', () => {
it('warning when start.ts lacks authkitMiddleware', async () => {
writeFixtureFile(testDir, 'src/start.ts', 'export default defineStart({})');
writeFixtureFile(testDir, 'src/start.ts', 'export default createStart({})');
const result = await checkAuthPatterns(
makeOptions(testDir),
makeFramework({ name: 'TanStack Start', expectedCallbackPath: '/auth/callback' }),
Expand All @@ -529,8 +559,9 @@ describe('checkAuthPatterns', () => {
testDir,
'src/start.ts',
`
import { createStart } from "@tanstack/react-start";
import { authkitMiddleware } from "@workos-inc/authkit-tanstack-start";
export default defineStart({ middleware: [authkitMiddleware()] });
export default createStart({ requestMiddleware: [authkitMiddleware()] });
`,
);
const result = await checkAuthPatterns(
Expand Down
16 changes: 11 additions & 5 deletions src/doctor/checks/auth-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,16 @@ function checkCallbackRouteMissing(ctx: CheckContext): AuthPatternFinding[] {
possiblePaths.push(join(ctx.installDir, 'app', 'routes', nested + `.${ext}`));
}
} else if (ctx.framework.name === 'TanStack Start') {
// Modern flat: src/routes/api.auth.callback.tsx Legacy nested: app/routes/api/auth/callback.tsx
// Flat: routes/api.auth.callback.tsx Nested: routes/api/auth/callback.tsx
// Both conventions work in both src/ and app/ directories
const segments = callbackPath.replace(/^\//, '').split('/');
const flat = segments.join('.');
const nested = segments.join('/');
for (const ext of ['tsx', 'jsx', 'ts', 'js']) {
possiblePaths.push(join(ctx.installDir, 'src', 'routes', `${flat}.${ext}`));
possiblePaths.push(join(ctx.installDir, 'app', 'routes', nested + `.${ext}`));
for (const prefix of ['src', 'app']) {
for (const ext of ['tsx', 'jsx', 'ts', 'js']) {
possiblePaths.push(join(ctx.installDir, prefix, 'routes', `${flat}.${ext}`));
possiblePaths.push(join(ctx.installDir, prefix, 'routes', nested + `.${ext}`));
}
}
}

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