Skip to content

Commit ef03f7b

Browse files
committed
docs: show edge-compatible auth pattern in examples
1 parent 339d2c1 commit ef03f7b

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,14 @@ npm install @nextlytics/core
4545
```typescript
4646
import { Nextlytics } from "@nextlytics/core/server";
4747
import { segmentBackend } from "@nextlytics/core/backends/segment";
48-
// Optional: import your auth library to track authenticated users
49-
import { auth } from "./lib/auth"; // next-auth
48+
// Nextlytics runs in Next.js middleware (Edge runtime), so it can't import
49+
// your main auth.ts if it pulls in Prisma, nodemailer, or other Node.js deps.
50+
// Instead, create a lightweight auth instance from your edge-safe base config.
51+
// See: https://authjs.dev/guides/edge-compatibility
52+
import NextAuth from "next-auth";
53+
import authConfig from "./auth.config";
54+
55+
const { auth } = NextAuth(authConfig);
5056

5157
export const { middleware, analytics } = Nextlytics({
5258
backends: [

packages/website/src/copy/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ export const packageManagers = {
1515
yarn: "yarn add @nextlytics/core",
1616
} as const;
1717

18-
const defaultAuthImport = 'import { auth } from "./lib/auth"; // next-auth';
18+
const defaultAuthImport = [
19+
"// Nextlytics runs in Edge middleware, so it can't import your main auth.ts",
20+
"// if it pulls in Prisma, nodemailer, or other Node.js-only deps.",
21+
"// Create a lightweight auth instance from your edge-safe base config.",
22+
"// See: https://authjs.dev/guides/edge-compatibility",
23+
'import NextAuth from "next-auth";',
24+
'import authConfig from "./auth.config";',
25+
"",
26+
"const { auth } = NextAuth(authConfig);",
27+
].join("\n");
1928
const defaultAuthCallback = [
2029
" async getUser() {",
2130
" const session = await auth();",
@@ -44,7 +53,6 @@ export function configSnippet(opts: ConfigSnippetOptions): string {
4453
"// src/nextlytics.ts",
4554
'import { Nextlytics } from "@nextlytics/core/server";',
4655
opts.backendImport,
47-
"// Optional: import your auth library to track authenticated users",
4856
authImport,
4957
"",
5058
"export const { middleware, analytics } = Nextlytics({",

0 commit comments

Comments
 (0)