Skip to content

Commit b410a1a

Browse files
fix(cli): use authClient in next when separate backend
1 parent 9b92fa5 commit b410a1a

File tree

1 file changed

+11
-0
lines changed
  • apps/cli/templates/auth/better-auth/web/react/next/src/app/dashboard

1 file changed

+11
-0
lines changed

apps/cli/templates/auth/better-auth/web/react/next/src/app/dashboard/page.tsx.hbs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import { redirect } from "next/navigation";
22
import Dashboard from "./dashboard";
33
import { headers } from "next/headers";
4+
{{#if (eq backend "self")}}
45
import { auth } from "@{{projectName}}/auth";
6+
{{/if}}
57
import { authClient } from "@/lib/auth-client";
68

79
export default async function DashboardPage() {
10+
{{#if (eq backend "self")}}
811
const session = await auth.api.getSession({
912
headers: await headers(),
1013
});
14+
{{else}}
15+
const session = await authClient.getSession({
16+
fetchOptions: {
17+
headers: await headers(),
18+
throw: true
19+
}
20+
});
21+
{{/if}}
1122

1223
if (!session?.user) {
1324
redirect("/login");

0 commit comments

Comments
 (0)