You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: www/docs/configuration/callbacks.md
+24-7
Original file line number
Diff line number
Diff line change
@@ -126,12 +126,15 @@ e.g. `getSession()`, `useSession()`, `/api/auth/session`
126
126
callbacks: {
127
127
/**
128
128
* @param{object}session Session object
129
-
* @param{object}user User object (if using database sessions)
129
+
* @param{object}token User object (if using database sessions)
130
130
* JSON Web Token (if not using database sessions)
131
131
* @return{object} Session that will be returned to the client
132
132
*/
133
-
asyncsession(session, user) {
134
-
session.foo='bar'// Add property to session
133
+
asyncsession(session, token) {
134
+
if(token?.access_token) {
135
+
// Add property to session, like an access_token from a provider
136
+
session.access_token=token.access_token
137
+
}
135
138
return session
136
139
}
137
140
}
@@ -140,7 +143,11 @@ callbacks: {
140
143
141
144
:::tip
142
145
When using JSON Web Tokens the `jwt()` callback is invoked before the `session()` callback, so anything you add to the
143
-
JSON Web Token will be immediately available in the session callback.
146
+
JSON Web Token will be immediately available in the session callback, like for example an `access_token` from a provider.
147
+
:::
148
+
149
+
:::tip
150
+
To better represent its value, when using a JWT session, the second parameter should be called `token` (This is the same thing you return from the `jwt` callback). If you use a database, call it `user`.
144
151
:::
145
152
146
153
:::warning
@@ -175,15 +182,25 @@ callbacks: {
175
182
* @return{object} JSON Web Token that will be saved
if (isSignIn) { token.auth_time=Math.floor(Date.now() /1000) }
185
+
// Add access_token to the token on signin in
186
+
if (account?.access_token) {
187
+
token.access_token=account.access_token
188
+
}
181
189
return token
182
190
}
183
191
}
184
192
...
185
193
```
186
194
195
+
:::tip
196
+
Use an if branch in jwt with checking for existence of any other params than token. If any of those exist, you call jwt for the first time.
197
+
This is a good place to add for example an `access_token` to your jwt, if you want to.
198
+
:::
199
+
200
+
:::tip
201
+
Check out the content of all the params in addition `token`, to see what info you have available on signin.
202
+
:::
203
+
187
204
:::warning
188
205
NextAuth.js does not limit how much data you can store in a JSON Web Token, however a ~**4096 byte limit** for all cookies on a domain is commonly imposed by browsers.
0 commit comments