Skip to content

Conversation

@balazsorban44
Copy link
Member

@balazsorban44 balazsorban44 commented Sep 30, 2022

This is an alternative proposal to #4893

Right now, we pass through all the values of a provider account to the DB, and it causes confusion/unforeseen breaks when a provider decides to return a new property.

To solve this, we can add an account property to the provider configuration, similar to the profile callback, to control what part of the account should be saved to the database.

Example:

// pages/api/auth/[...nextauth].ts
import NextAuth from "next-auth"
import AzureAD from "next-auth/providers/azure-ad"

// this can be in `next-auth/providers/azure-ad`
interface AzureADAccount {
  ext_expires_in: number
}

declare module "next-auth" {
  interface Account extends AzureADAccount {}
}


export default NextAuth({
  providers: [
    AzureAD({
      ...
      // this would show a type error, because we required `ext_expires_in`
      account({ ext_expires_in, ...a }) {
        return a
      }
      // account: "minimal" // conversely, we can also only allow the most common properties
    })
  ]
})

Closes #4893

@vercel
Copy link

vercel bot commented Sep 30, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
next-auth ⬜️ Ignored (Inspect) Sep 30, 2022 at 1:58PM (UTC)

@github-actions github-actions bot added adapters Changes related to the core code concerning database adapters core Refers to `@auth/core` providers labels Sep 30, 2022
@github-actions github-actions bot added the TypeScript Issues relating to TypeScript label Sep 30, 2022
@balazsorban44
Copy link
Member Author

cc @palminha curious what you think. This would still introduce a new config option but would be already familiar since it's similar to the profile() callback and gives full control to the developer.

We could change the default value to "minimal" in a future major release.

It would align with the profile callback, which also only maps  id, name, image, and email by default. 👍

Comment on lines +243 to +259
if (version?.startsWith("1")) {
return {
...required,
oauth_token_secret: rest.oauth_token_secret,
oauth_token: rest.oauth_token,
}
}
return {
...required,
access_token: rest.access_token,
token_type: rest.token_type,
id_token: rest.id_token,
refresh_token: rest.refresh_token,
scope: rest.scope,
expires_at: rest.expires_at,
session_state: rest.session_state,
}
Copy link
Member Author

Choose a reason for hiding this comment

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

These are the values currently in the default schemas.

@balazsorban44
Copy link
Member Author

Closing as discussed with @ThangHuuVu. With some minor changes, this will be part of @auth/core, so the intention is to still simplify the default account model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adapters Changes related to the core code concerning database adapters core Refers to `@auth/core` providers TypeScript Issues relating to TypeScript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants