Skip to content

Commit

Permalink
feat(core): pass profile to linkAccount event (#4242)
Browse files Browse the repository at this point in the history
Co-authored-by: Nico Domino <yo@ndo.dev>
  • Loading branch information
michaelhays and ndom91 committed Jun 24, 2022
1 parent e8827cb commit d8d9ab9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/docs/configuration/events.md
Expand Up @@ -53,6 +53,7 @@ The message object will contain:

- `user`: The user object from your adapter.
- `account`: The object returned from the provider.
- `profile`: The object returned from the `profile` callback of the OAuth provider.

### session

Expand Down
4 changes: 2 additions & 2 deletions packages/next-auth/src/core/lib/callback-handler.ts
Expand Up @@ -155,7 +155,7 @@ export default async function callbackHandler(params: {
// If the user is already signed in and the OAuth account isn't already associated
// with another user account then we can go ahead and link the accounts safely.
await linkAccount({ ...account, userId: user.id })
await events.linkAccount?.({ user, account })
await events.linkAccount?.({ user, account, profile })

// As they are already signed in, we don't need to do anything after linking them
return { session, user, isNewUser }
Expand Down Expand Up @@ -205,7 +205,7 @@ export default async function callbackHandler(params: {
await events.createUser?.({ user })

await linkAccount({ ...account, userId: user.id })
await events.linkAccount?.({ user, account })
await events.linkAccount?.({ user, account, profile })

session = useJwtSession
? {}
Expand Down
6 changes: 5 additions & 1 deletion packages/next-auth/src/core/types.ts
Expand Up @@ -389,7 +389,11 @@ export interface EventCallbacks {
signOut: (message: { session: Session; token: JWT }) => Awaitable<void>
createUser: (message: { user: User }) => Awaitable<void>
updateUser: (message: { user: User }) => Awaitable<void>
linkAccount: (message: { user: User; account: Account }) => Awaitable<void>
linkAccount: (message: {
user: User
account: Account
profile: User
}) => Awaitable<void>
/**
* The message object will contain one of these depending on
* if you use JWT or database persisted sessions:
Expand Down

1 comment on commit d8d9ab9

@vercel
Copy link

@vercel vercel bot commented on d8d9ab9 Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.