VK Provider email problems #1617
Unanswered
xxtereshko
asked this question in
Help
Replies: 2 comments 1 reply
-
please provide a reproduction so we can help you |
Beta Was this translation helpful? Give feedback.
1 reply
-
VK uses email or phone for auth. New users in vk don't have email. For fast solution: You can add custom provider to your configuration Use bellow code: import {OAuthConfig, OAuthUserConfig} from 'next-auth/providers';
interface VkProfile {
response: Array<{
id: number;
first_name: string;
last_name: string;
photo_100: string;
can_access_closed: boolean;
is_closed: boolean;
}>;
}
export default function VK<P extends Record<string, any> = VkProfile>(
options: OAuthUserConfig<P>,
): OAuthConfig<P> {
const apiVersion = '5.126'; // https://vk.com/dev/versions
return {
id: 'vk',
name: 'VK',
type: 'oauth',
authorization: `https://oauth.vk.com/authorize?scope=email&v=${apiVersion}`,
token: {
url: `https://oauth.vk.com/access_token?v=${apiVersion}`,
async request({client, params, checks, provider}) {
// exclude user_id and email from response
const {user_id, email, ...tokens} = await client.oauthCallback(
provider.callbackUrl,
params,
checks,
{
exchangeBody: {
client_id: options.clientId,
client_secret: options.clientSecret,
},
},
);
return {tokens};
},
},
userinfo: `https://api.vk.com/method/users.get?fields=photo_100&v=${apiVersion}`,
profile(result: P) {
const profile = result.response?.[0] ?? {};
return {
id: profile.id,
name: [profile.first_name, profile.last_name]
.filter(Boolean)
.join(' '),
email: null,
image: profile.photo_100,
};
},
options,
};
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
VK Provider email problem
I can not receive email after authorization.
What are you trying to do
I do everything according to the documentation with example project . Email scope is configured. When authorizing on the VK side, the application requests access rights to the email. After authorization and redirection to my application, everything is fine, I even get a link to my profile avatar. But there is a problem, in the session object, the email field is null.
Beta Was this translation helpful? Give feedback.
All reactions