How to access callback (twitter or google) repose values if needed extra data from that.
[v2] Hello, we have use case where I need to access callback response raw object example from twitter callback currently storing user id, email access token, profile pic etc but not screen_name , auth verifier, access_token, access_secret.
One option is you can add a custom profile() function to a provider, like this:
import NextAuth from 'next-auth'
import Providers from 'next-auth/providers'
const options = {
site: 'https://example.com'
providers: [
Providers.Twitter({
clientId: process.env.GOOGLE_ID,
clientSecret: process.env.GOOGLE_SECRET,
profile: (profile) => {
return {
id: profile.id,
name: profile.name,
email: profile.email,
image: profile.profile_image_url_https.replace(/_normal\.jpg$/, '.jpg')
}
},
}),
],
database: process.env.DATABASE_URI
}
You can see what the default handlers look like here: https://github.com/iaincollins/next-auth/blob/master/src/providers
However if you return additional fields they are not persisted in the database, as they don't map to the model (and it's not really possible to ship with a model that would support all providers).
I am thinking of make this method async so that you could do your own thing here, like save it to a database table. Also I'll be improving the handling so it generates an error if the email address or account ID is missing.
I'm looking at ways to make saving this info easier at some point, perhaps a single function triggered on account creation, although that might not make it into the initial release.
(and it's not really possible to ship with a model that would support all providers).
Id is a property that is present in every provider and yet it's not persisted in the database (see: https://github.com/iaincollins/next-auth/blob/master/src/server/lib/oauth/callback.js#L87)

First object is the profile object from the provider, the second is the session.
Am I doing something wrong? Is it intended? I'm having to workaround and strip the id from the avatar url.
@DevNvll Ah, so you might want to take a look at the models, you can find them here: https://github.com/iaincollins/next-auth/tree/master/src/adapters/typeorm/models
The models and schemas are something that's yet to be documented and they are not final yet - but are fairly close to being final.
The property you want is stored in account.providerAccountId.
It is not returned in the profile callback. Like RefreshToken and Access token, it is handled automatically internally. This is something that is likely to change over time.
I've pasted the schema from account below, and added some comments.
export const AccountSchema = {
name: 'Account',
target: Account,
columns: {
id: {
// Unique ID for this entry in the account table (in MongoDB is type: ObjectID)
primary: true,
type: 'int',
generated: true
},
providerCompoundId: {
// A hash of provider name (e.g. 'google') and provider account ID (e.g. '1234')
// Being unique, it ensures that a single oAuth account can only be linked to one user
// Note: A user can have multiple oAuth accounts with the same (and/or different) providers
type: 'varchar',
unique: true
},
userId: {
// The user ID (in MongoDB is type: ObjectID)
type: 'int'
},
providerId: {
// The name of the provider (e.g. 'google')
type: 'varchar'
},
providerType: {
// The type of provider (currently always 'oauth')
type: 'varchar'
},
providerAccountId: {
// The ID of the user account with the provider (e.g. '1234'; usually but not always an int)
type: 'varchar'
},
refreshToken: {
// Stored as type 'text' as with some providers is can be too large for varchar
type: 'text',
nullable: true
},
accessToken: {
// Stored as type 'text' as with some providers is can be too large for varchar
type: 'text'
},
accessTokenExpires: {
// @TODO AccessToken expiry is not yet tracked (key/value varies across providers)
type: 'timestamp',
nullable: true
}
}
}
I think this is resolved now.