@@ -31,16 +31,16 @@ Below is a sample implementation using Google's Identity Provider. Please note t
3131<Code >
3232 <Code.Next >
3333
34- ``` ts
35- import { Auth } from " @ auth/core "
36- import { type TokenSet } from " @ auth/core /types"
37- import Google from " @ auth/core /providers/google"
34+ ``` ts filename="./auth.ts"
35+ import NextAuth from " next- auth"
36+ import { type TokenSet } from " next- auth/types"
37+ import Google from " next- auth/providers/google"
3838
39- export default Auth ( new Request ( " https://example.com " ), {
39+ export const { handlers, auth } = NextAuth ( {
4040 providers: [
4141 Google ({
42- clientId: process .env .GOOGLE_ID ,
43- clientSecret: process .env .GOOGLE_SECRET ,
42+ clientId: process .env .AUTH_GOOGLE_ID ,
43+ clientSecret: process .env .AUTH_GOOGLE_SECRET ,
4444 authorization: { params: { access_type: " offline" , prompt: " consent" } },
4545 }),
4646 ],
@@ -64,8 +64,8 @@ export default Auth(new Request("https://example.com"), {
6464 const response = await fetch (" https://oauth2.googleapis.com/token" , {
6565 headers: { " Content-Type" : " application/x-www-form-urlencoded" },
6666 body: new URLSearchParams ({
67- client_id: process .env .GOOGLE_ID ,
68- client_secret: process .env .GOOGLE_SECRET ,
67+ client_id: process .env .AUTH_GOOGLE_ID ,
68+ client_secret: process .env .AUTH_GOOGLE_SECRET ,
6969 grant_type: " refresh_token" ,
7070 refresh_token: token .refresh_token ,
7171 }),
@@ -98,13 +98,13 @@ export default Auth(new Request("https://example.com"), {
9898 },
9999})
100100
101- declare module " @ auth/core/types " {
101+ declare module " next- auth" {
102102 interface Session {
103103 error? : " RefreshAccessTokenError"
104104 }
105105}
106106
107- declare module " @ auth/core /jwt" {
107+ declare module " next- auth/jwt" {
108108 interface JWT {
109109 access_token: string
110110 expires_at: number
@@ -124,21 +124,21 @@ Using the database strategy is very similar, but instead of preserving the `acce
124124<Code >
125125 <Code.Next >
126126
127- ``` ts
128- import { Auth } from " @ auth/core "
129- import { type TokenSet } from " @ auth/core /types"
130- import Google from " @ auth/core /providers/google"
127+ ``` ts filename="./auth.ts"
128+ import NextAuth from " next- auth"
129+ import { type TokenSet } from " next- auth/types"
130+ import Google from " next- auth/providers/google"
131131import { PrismaAdapter } from " @auth/prisma-adapter"
132132import { PrismaClient } from " @prisma/client"
133133
134134const prisma = new PrismaClient ()
135135
136- export default Auth ( new Request ( " https://example.com " ), {
136+ export const { handlers, auth } = NextAuth ( {
137137 adapter: PrismaAdapter (prisma ),
138138 providers: [
139139 Google ({
140- clientId: process .env .GOOGLE_ID ,
141- clientSecret: process .env .GOOGLE_SECRET ,
140+ clientId: process .env .AUTH_GOOGLE_ID ,
141+ clientSecret: process .env .AUTH_GOOGLE_SECRET ,
142142 authorization: { params: { access_type: " offline" , prompt: " consent" } },
143143 }),
144144 ],
@@ -155,8 +155,8 @@ export default Auth(new Request("https://example.com"), {
155155 const response = await fetch (" https://oauth2.googleapis.com/token" , {
156156 headers: { " Content-Type" : " application/x-www-form-urlencoded" },
157157 body: new URLSearchParams ({
158- client_id: process .env .GOOGLE_ID ,
159- client_secret: process .env .GOOGLE_SECRET ,
158+ client_id: process .env .AUTH_GOOGLE_ID ,
159+ client_secret: process .env .AUTH_GOOGLE_SECRET ,
160160 grant_type: " refresh_token" ,
161161 refresh_token: google .refresh_token ,
162162 }),
@@ -191,13 +191,13 @@ export default Auth(new Request("https://example.com"), {
191191 },
192192})
193193
194- declare module " @ auth/core/types " {
194+ declare module " next- auth" {
195195 interface Session {
196196 error? : " RefreshAccessTokenError"
197197 }
198198}
199199
200- declare module " @ auth/core /jwt" {
200+ declare module " next- auth/jwt" {
201201 interface JWT {
202202 access_token: string
203203 expires_at: number
@@ -212,7 +212,7 @@ declare module "@auth/core/jwt" {
212212
213213### Client Side
214214
215- The ` RefreshAccessTokenError ` error that is caught in the ` refreshAccessToken() ` method is passed to the client. This means that you can direct the user to the sign-in flow if we cannot refresh their token.
215+ The ` RefreshAccessTokenError ` error that is caught in the ` refreshAccessToken() ` method is passed to the client. This means that you can direct the user to the sign-in flow if we cannot refresh their token. Don't forget, calling ` useSession ` client-side, for example, requires your component is wrapped with the ` <SessionProvider /> ` .
216216
217217We can handle this functionality as a side effect:
218218
0 commit comments