fix(oauth): fix VK token URL (.ru -> .com), add error logging to callbacks
This commit is contained in:
@@ -33,7 +33,7 @@ export const vkOAuthConfig = {
|
|||||||
clientId: process.env.VK_CLIENT_ID || '',
|
clientId: process.env.VK_CLIENT_ID || '',
|
||||||
clientSecret: process.env.VK_CLIENT_SECRET || '',
|
clientSecret: process.env.VK_CLIENT_SECRET || '',
|
||||||
authUrl: 'https://id.vk.com/oauth2/auth',
|
authUrl: 'https://id.vk.com/oauth2/auth',
|
||||||
tokenUrl: 'https://id.vk.ru/oauth2/auth',
|
tokenUrl: 'https://id.vk.com/oauth2/auth',
|
||||||
scope: 'email phone',
|
scope: 'email phone',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export const GET: APIRoute = async ({ url, request }) => {
|
|||||||
const storedState = getCookieValue(cookieHeader, 'oauth_state');
|
const storedState = getCookieValue(cookieHeader, 'oauth_state');
|
||||||
|
|
||||||
if (!code || !state || !verifier || state !== storedState) {
|
if (!code || !state || !verifier || state !== storedState) {
|
||||||
|
console.error('[OAuth VK] Validation failed:', { hasCode: !!code, hasState: !!state, hasVerifier: !!verifier, stateMatch: state === storedState });
|
||||||
return new Response(JSON.stringify({ error: 'Invalid or missing parameters' }), {
|
return new Response(JSON.stringify({ error: 'Invalid or missing parameters' }), {
|
||||||
status: 400,
|
status: 400,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@@ -42,7 +43,9 @@ export const GET: APIRoute = async ({ url, request }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!tokenRes.ok) {
|
if (!tokenRes.ok) {
|
||||||
return new Response(JSON.stringify({ error: 'Token exchange failed' }), {
|
const errorText = await tokenRes.text();
|
||||||
|
console.error('[OAuth VK] Token exchange failed:', tokenRes.status, errorText);
|
||||||
|
return new Response(JSON.stringify({ error: 'Token exchange failed', details: errorText }), {
|
||||||
status: 500,
|
status: 500,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export const GET: APIRoute = async ({ url, request }) => {
|
|||||||
const storedState = getCookieValue(cookieHeader, 'oauth_state');
|
const storedState = getCookieValue(cookieHeader, 'oauth_state');
|
||||||
|
|
||||||
if (!code || !state || !verifier || state !== storedState) {
|
if (!code || !state || !verifier || state !== storedState) {
|
||||||
|
console.error('[OAuth Yandex] Validation failed:', { hasCode: !!code, hasState: !!state, hasVerifier: !!verifier, stateMatch: state === storedState });
|
||||||
return new Response(JSON.stringify({ error: 'Invalid or missing parameters' }), {
|
return new Response(JSON.stringify({ error: 'Invalid or missing parameters' }), {
|
||||||
status: 400,
|
status: 400,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@@ -43,7 +44,9 @@ export const GET: APIRoute = async ({ url, request }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!tokenRes.ok) {
|
if (!tokenRes.ok) {
|
||||||
return new Response(JSON.stringify({ error: 'Token exchange failed' }), {
|
const errorText = await tokenRes.text();
|
||||||
|
console.error('[OAuth Yandex] Token exchange failed:', tokenRes.status, errorText);
|
||||||
|
return new Response(JSON.stringify({ error: 'Token exchange failed', details: errorText }), {
|
||||||
status: 500,
|
status: 500,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user