Skip to content

Commit eed0001

Browse files
fix(ts): adjust properties on default interfaces (#1794)
* fix(ts): adjust properties on default interfaces * fix(ts): make expires also optional * fix(ts): don't require default session/jwt fields * fix(ts): make all default fields optional
1 parent a2705fb commit eed0001

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

types/index.d.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,15 @@ export interface PagesOptions {
364364
newUser?: string
365365
}
366366

367+
export interface DefaultSession extends Record<string, unknown> {
368+
user?: {
369+
name?: string | null
370+
email?: string | null
371+
image?: string | null
372+
}
373+
expires?: string
374+
}
375+
367376
/**
368377
* Returned by `useSession`, `getSession`, returned by the `session` callback
369378
* and also the shape received as a prop on the `Provider` React Context
@@ -373,11 +382,7 @@ export interface PagesOptions {
373382
* [`Provider`](https://next-auth.js.org/getting-started/client#provider) |
374383
* [`session` callback](https://next-auth.js.org/configuration/callbacks#jwt-callback)
375384
*/
376-
export interface Session extends Record<string, unknown> {
377-
user?: User
378-
accessToken?: string
379-
expires: string
380-
}
385+
export interface Session extends Record<string, unknown>, DefaultSession {}
381386

382387
/** [Documentation](https://next-auth.js.org/configuration/options#session) */
383388
export interface SessionOptions {

types/jwt.d.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import { JWT as JoseJWT, JWE } from "jose"
22
import { NextApiRequest } from "./internals/utils"
33

4+
export interface DefaultJWT extends Record<string, unknown> {
5+
name?: string | null
6+
email?: string | null
7+
picture?: string | null
8+
sub?: string
9+
}
10+
411
/**
512
* Returned by the `jwt` callback and `getToken`, when using JWT sessions
613
*
714
* [`jwt` callback](https://next-auth.js.org/configuration/callbacks#jwt-callback) | [`getToken`](https://next-auth.js.org/tutorials/securing-pages-and-api-routes#using-gettoken)
815
*/
9-
export interface JWT extends Record<string, unknown> {
10-
name?: string | null
11-
email?: string | null
12-
picture?: string | null
13-
}
16+
export interface JWT extends Record<string, unknown>, DefaultJWT {}
1417

1518
export interface JWTEncodeParams {
1619
token?: JWT

0 commit comments

Comments
 (0)