add yandex button
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
'use server'
|
||||
|
||||
import { API_BASE_URL } from '@/app/actions/definitions';
|
||||
import { createSession } from '@/app/actions/session';
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
|
||||
export async function YandexAuthorization(data: any, codeVerifier: string) {
|
||||
|
||||
console.log(data);
|
||||
console.log(codeVerifier);
|
||||
const { code, state, device_id } = data
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/api/v1/yandex/authorization/${code}/${state}/${codeVerifier}/${device_id}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
}
|
||||
});
|
||||
if (response.ok) {
|
||||
let parsed = await response.json();
|
||||
console.log(parsed);
|
||||
if (parsed.message_desc === 'Operation successful') {
|
||||
/* await createSession(parsed.message_body.token, email); */
|
||||
} else {
|
||||
throw (`${parsed.message_code}`);
|
||||
}
|
||||
} else {
|
||||
throw ('request-ended-with-an-error');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
const errors: Record<string, string> = {}
|
||||
|
||||
switch (error) {
|
||||
case '2':
|
||||
errors['server'] = 'password-does-not-match'
|
||||
break;
|
||||
|
||||
case '4':
|
||||
errors['server'] = 'email-not-found'
|
||||
break;
|
||||
|
||||
default:
|
||||
errors['server'] = 'request-ended-with-an-error'
|
||||
break;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
redirect('/pages/dashboard');
|
||||
}
|
||||
Reference in New Issue
Block a user