Skip to content

Commit b23cbd4

Browse files
fix(cli): use authClient in tanstack start when separate backend
1 parent e499dce commit b23cbd4

File tree

1 file changed

+20
-1
lines changed
  • apps/cli/templates/auth/better-auth/web/react/tanstack-start/src/middleware

1 file changed

+20
-1
lines changed

apps/cli/templates/auth/better-auth/web/react/tanstack-start/src/middleware/auth.ts.hbs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{#if (eq backend "self")}}
12
import { auth } from "@{{projectName}}/auth";
23
import { createMiddleware } from "@tanstack/react-start";
34

@@ -9,4 +10,22 @@ export const authMiddleware = createMiddleware().server(async ({ next, request }
910
return next({
1011
context: { session }
1112
})
12-
})
13+
})
14+
{{else}}
15+
import { authClient } from "@/lib/auth-client";
16+
import { createMiddleware } from "@tanstack/react-start";
17+
18+
export const authMiddleware = createMiddleware().server(
19+
async ({ next, request }) => {
20+
const session = await authClient.getSession({
21+
fetchOptions: {
22+
headers: request.headers,
23+
throw: true
24+
}
25+
})
26+
return next({
27+
context: { session },
28+
});
29+
},
30+
);
31+
{{/if}}

0 commit comments

Comments
 (0)