|
1 |
| -// Minimum TypeScript Version: 3.5 |
| 1 | +// Minimum TypeScript Version: 3.6 |
2 | 2 |
|
3 | 3 | /// <reference types="node" />
|
4 | 4 |
|
@@ -111,7 +111,7 @@ export interface NextAuthOptions {
|
111 | 111 | *
|
112 | 112 | * [Documentation](https://next-auth.js.org/configuration/options#events) | [Events documentation](https://next-auth.js.org/configuration/events)
|
113 | 113 | */
|
114 |
| - events?: EventsOptions |
| 114 | + events?: Partial<JWTEventCallbacks | SessionEventCallbacks> |
115 | 115 | /**
|
116 | 116 | * By default NextAuth.js uses a database adapter that uses TypeORM and supports MySQL, MariaDB, Postgres and MongoDB and SQLite databases.
|
117 | 117 | * An alternative adapter that uses Prisma, which currently supports MySQL, MariaDB and Postgres, is also included.
|
@@ -350,20 +350,61 @@ export interface CookiesOptions {
|
350 | 350 | }
|
351 | 351 |
|
352 | 352 | /** [Documentation](https://next-auth.js.org/configuration/events) */
|
353 |
| -export type EventType = |
354 |
| - | "signIn" |
355 |
| - | "signOut" |
356 |
| - | "createUser" |
357 |
| - | "updateUser" |
358 |
| - | "linkAccount" |
359 |
| - | "session" |
360 |
| - | "error" |
| 353 | +export type EventCallback<MessageType = unknown> = ( |
| 354 | + message: MessageType |
| 355 | +) => Promise<void> |
361 | 356 |
|
362 |
| -/** [Documentation](https://next-auth.js.org/configuration/events) */ |
363 |
| -export type EventCallback = (message: any) => Promise<void> |
| 357 | +/** |
| 358 | + * If using a `credentials` type auth, the user is the raw response from your |
| 359 | + * credential provider. |
| 360 | + * For other providers, you'll get the User object from your adapter, the account, |
| 361 | + * and an indicator if the user was new to your Adapter. |
| 362 | + */ |
| 363 | +export interface SignInEventMessage { |
| 364 | + user: User |
| 365 | + account: Account |
| 366 | + isNewUser?: boolean |
| 367 | +} |
364 | 368 |
|
365 |
| -/** [Documentation](https://next-auth.js.org/configuration/events) */ |
366 |
| -export type EventsOptions = Partial<Record<EventType, EventCallback>> |
| 369 | +export interface LinkAccountEventMessage { |
| 370 | + user: User |
| 371 | + providerAccount: Record<string, unknown> |
| 372 | +} |
| 373 | + |
| 374 | +/** |
| 375 | + * The various event callbacks you can register for from next-auth |
| 376 | + */ |
| 377 | +export interface CommonEventCallbacks { |
| 378 | + signIn: EventCallback<SignInEventMessage> |
| 379 | + createUser: EventCallback<User> |
| 380 | + updateUser: EventCallback<User> |
| 381 | + linkAccount: EventCallback<LinkAccountEventMessage> |
| 382 | + error: EventCallback |
| 383 | +} |
| 384 | +/** |
| 385 | + * The event callbacks will take this form if you are using JWTs: |
| 386 | + * signOut will receive the JWT and session will receive the session and JWT. |
| 387 | + */ |
| 388 | +export interface JWTEventCallbacks extends CommonEventCallbacks { |
| 389 | + signOut: EventCallback<JWT> |
| 390 | + session: EventCallback<{ |
| 391 | + session: Session |
| 392 | + jwt: JWT |
| 393 | + }> |
| 394 | +} |
| 395 | +/** |
| 396 | + * The event callbacks will take this form if you are using Sessions |
| 397 | + * and not using JWTs: |
| 398 | + * signOut will receive the underlying DB adapter's session object, and session |
| 399 | + * will receive the NextAuth client session with extra data. |
| 400 | + */ |
| 401 | +export interface SessionEventCallbacks extends CommonEventCallbacks { |
| 402 | + signOut: EventCallback<Session | null> |
| 403 | + session: EventCallback<{ session: Session }> |
| 404 | +} |
| 405 | +export type EventCallbacks = JWTEventCallbacks | SessionEventCallbacks |
| 406 | + |
| 407 | +export type EventType = keyof EventCallbacks |
367 | 408 |
|
368 | 409 | /** [Documentation](https://next-auth.js.org/configuration/pages) */
|
369 | 410 | export interface PagesOptions {
|
|
0 commit comments