I have written custom adapter.
In that, we have createUser method which accepts profile.
This profile object has only 3 default values (name, image, email).
async function createUser(profile) {
console.log('createUser')
console.log(profile)
const user = await userObj.createUser(profile)
//console.log(user)
return user
}
I want to get more values in profile object in createUser method in custom adapter.
In scope as you see i have added address and birthday, i dont get them in profile object in createUser method.
Providers.Google({
scope : 'https://www.googleapis.com/auth/user.addresses.read https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/user.birthday.read',
clientId:
clientSecret:
}),
So my question is how to add more values from scope in profile object?
@iaincollins updated my question.
Currently, storing other data is not supported - having a generic way to do this would be non-trivial and there isn't practically a way to do it that would automatically work for all providers, properties and use cases.
However, can can persist additional data returned from OAuth providers using callbacks and / or events in the database (e.g. by accessing the profile object) - e.g. doing an INSERT / UPDATE of that data agains the user - though we currently have an example that shows how best to do this. It's something we could do more to make it easier and a number of options are currently under consideration for this, including a profile callback that could also be used for other things.
Thank you for your answer.
I can work in callbacks or events to store extra data.
Another point is, these extra values like birthday/address is not accessible in callback?
Here is values in SignIn callback (Order => user, account, profile).
TextRow {
id: 82,
name: 'Atul xxx',
email: '[email protected]',
email_verified: null,
image: 'https://lh3.googleusercontent.com/a-/AOh14GjXOfrF9q6pS4aPPoF8ozg',
created_at: 2020-08-22T05:20:27.234Z,
updated_at: 2020-08-22T05:20:27.234Z
} {
provider: 'google',
type: 'oauth',
id: '10239429234',
refreshToken: undefined,
accessToken: 'ya29Pth6u-tMzbSkL-3PNABn71GA38FZnp14ooCiaKcEzS8mSfAK-bgf6Sr45hwNo9ZAB3tkgLWXVKnOxdSlYvHv1zyuwQrqfF25EKmTAbDUK7ZrarulJNU4x8Cc3vCU',
accessTokenExpires: null
} {
id: '1023234',
email: '[email protected]',
verified_email: true,
name: 'Atul',
given_name: 'Atul',
family_name: 'XXXXXX',
picture: 'https://lh3.googleusercontent.com/a-/AOh14GjXO61ikUnJrF9q6pS4aPPoF8ozg',
locale: 'en-GB'
}
That looks good to me!
I'm not familiar with the birthday property in Google profiles, but everything returned from the OAuth provider should be in that last object if it's in the scope for the provider - at a glance, everything you are doing looks correct to me and I would expect that to work.
It might be worth checking that a birthday is associated with that account.
Confusingly, there are several different ways to get user information using Google, so if it's configured and not working it's possible this endpoint does not return that data, and that you would need to make another request to different endpoint (using the access token) to obtain it.
I am not sure but based on what I've read I suspect it might only be returned from Google's People API. If that is true, you'd still need to specify the scope as you have done, but then you'd also need to enable the API and use the Access Token to fetch this data in the callback.
(This seems a bit clunky, a few other providers have similar issues for certain fields, for some reason.)
I tried to making my brithday and address public but still i dont see them in SignIn callback.
I dont get any extra added scopes in profile object except the default one.
You may try at your end if you have some time. :)
Would it be at all possible to allow overwriting the default profile that's passed to the createUser() method in a custom adapter? I'm trying to get Next Auth working with FaunaDB and a feature like this would be fantastic! Currently callbacks work but somewhat defeat the purpose of using a custom adapter to begin with.
Hi there! It looks like this issue hasn't had any activity for a while. It will be closed if no further activity occurs. If you think your issue is still relevant, feel free to comment on it to keep ot open. Thanks!
Most helpful comment
Would it be at all possible to allow overwriting the default
profilethat's passed to thecreateUser()method in a custom adapter? I'm trying to get Next Auth working with FaunaDB and a feature like this would be fantastic! Currently callbacks work but somewhat defeat the purpose of using a custom adapter to begin with.