Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profile to linkAccount event data #4242

Merged
merged 2 commits into from Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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