@@ -12,8 +12,11 @@ export function SetupCode({ providerId, providerName, highlight }: Props) {
12
12
return (
13
13
< Code >
14
14
< Code . Next >
15
+ In Next.js we recommend setting up your configuration in a file in the root of your repository, like at{ " " }
16
+ < code > auth.ts</ code > .
17
+ < br />
15
18
< Pre
16
- data-filename = "@ /auth"
19
+ data-filename = ". /auth.ts "
17
20
data-theme = "default"
18
21
data-copy = ""
19
22
data-language = "tsx"
@@ -23,15 +26,32 @@ export function SetupCode({ providerId, providerName, highlight }: Props) {
23
26
import NextAuth from "next-auth"
24
27
import ${ providerName } from "next-auth/providers/${ providerId } "
25
28
26
- export const { signIn, signOut, auth } = NextAuth({
29
+ export const { handlers, signIn, signOut, auth } = NextAuth({
27
30
providers: [${ providerName } ],
28
31
})` ) ,
29
32
} }
30
33
/>
34
+ < br />
35
+ Add the < code > handlers</ code > which < code > NextAuth</ code > returns to
36
+ your < code > api/auth/[...nextauth]/route.ts</ code > file so that Auth.js
37
+ can run on any incoming request.
38
+ < Pre
39
+ data-filename = "./app/api/auth/[...nextauth]/route.ts"
40
+ data-theme = "default"
41
+ data-copy = ""
42
+ data-language = "tsx"
43
+ icon = { TSIcon }
44
+ dangerouslySetInnerHTML = { {
45
+ __html : highlight ( `
46
+ import { handlers } from "@/auth"
47
+ export const { GET, POST } = handlers
48
+ ` ) ,
49
+ } }
50
+ />
31
51
</ Code . Next >
32
52
< Code . Svelte >
33
53
In SvelteKit you should also setup your Auth.js configuration in a file
34
- at ` /src/auth.ts` .
54
+ at < code > /src/auth.ts</ code > .
35
55
< br />
36
56
< Pre
37
57
data-filename = "./src/auth.ts"
@@ -44,7 +64,7 @@ export const { signIn, signOut, auth } = NextAuth({
44
64
import { SvelteKitAuth } from "@auth/sveltekit"
45
65
import ${ providerName } from "@auth/sveltekit/providers/${ providerId } "
46
66
47
- export const { handle } = SvelteKitAuth({
67
+ export const { handle, signIn } = SvelteKitAuth({
48
68
providers: [${ providerName } ],
49
69
}) ` ) ,
50
70
} }
0 commit comments