add new yandex auth

This commit is contained in:
smanylov
2026-03-11 18:21:19 +07:00
parent e8f4f9939f
commit 9fbb74ba60
8 changed files with 156 additions and 20 deletions
+38
View File
@@ -0,0 +1,38 @@
import { NextResponse } from 'next/server';
export async function POST(request: Request) {
const { code } = await request.json();
try {
const response = await fetch('https://oauth.yandex.ru/token', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({
grant_type: 'authorization_code',
code,
client_id: 'b356a7ceac0f4c50a3b434220f86bce0',
client_secret: '0800f7774f7d4e19ad4b434f10afd4ab',
})
});
const data = await response.json();
console.log(data);
if (data.access_token) {
const userInfo = await fetch('https://login.yandex.ru/info?format=json', {
headers: { 'Authorization': `OAuth ${data.access_token}` }
}).then(r => r.json());
console.log(userInfo);
// Тут мне нужно будет отправить сделать запрос в бек с userInfo и там уже редиректить на дешборд
return NextResponse.json({ success: true });
}
} catch (error) {
console.error('Token exchange failed:', error);
}
return NextResponse.json({ success: false }, { status: 400 });
}