diff --git a/luckydiamond/src/assets/js/authentication/AuthService.js b/luckydiamond/src/assets/js/authentication/AuthService.js index 981fa8d..9c64718 100644 --- a/luckydiamond/src/assets/js/authentication/AuthService.js +++ b/luckydiamond/src/assets/js/authentication/AuthService.js @@ -1,12 +1,21 @@ import { Post } from '../rest/RestMethods.js'; import { BackendApiUrl } from '@/properties/Сonfig.js'; -export function - LogIn(authCode) { - return Post(BackendApiUrl + "/LogIn", { code: authCode }).then((data) => { - console.log(data); - return data; - }).catch(error => { - console.log(error) - }); -} +// export function +// LogIn(authCode) { +// return Post(BackendApiUrl + "/LogIn", { code: authCode }).then((data) => { +// console.log(data); +// return data; +// }).catch(error => { +// console.log(error) +// }); +// } +export async function LogIn(authCode) { + try { + const response = await Post(BackendApiUrl + "/Authorize/LogIn", { code: authCode }); + console.log(response); + return response; + } catch (error) { + console.error('Ошибка в LogIn:', error); + } +} \ No newline at end of file diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index 5178026..2bdb16c 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -1,21 +1,41 @@ export async function Post(url = "", data = {}) { - // Default options are marked with * - try { - const response = await fetch(url, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - redirect: "follow", - referrerPolicy: "no-referrer", - body: JSON.stringify(data), - }); - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } - return await response.json(); - } catch (error) { - console.log("Fetch error:", error); - throw error; // Re-throw the error so it can be caught by the calling function - } + + // Default options are marked with * + // try { + // const response = await fetch(url, { + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // }, + // redirect: "follow", + // referrerPolicy: "no-referrer", + // body: JSON.stringify(data), + // }); + // if (!response.ok) { + // console.log("Fetch error:", response.status); + // } + // return await response.json(); + // } catch (error) { + // console.log("Fetch error:", error); + // } + + var myHeaders = new Headers(); + myHeaders.append("Content-Type", "application/json"); + + var raw = JSON.stringify(data); + + + var requestOptions = { + method: 'POST', + headers: myHeaders, + body: raw, + redirect: 'follow' + }; + + fetch(url, requestOptions) + .then(response => response.text()) + .then(result => console.log(result)) + .catch(error => console.log('error', error)); + + } \ No newline at end of file diff --git a/luckydiamond/src/components/HeaderComponent.vue b/luckydiamond/src/components/HeaderComponent.vue index 2d74dee..c3ea61f 100644 --- a/luckydiamond/src/components/HeaderComponent.vue +++ b/luckydiamond/src/components/HeaderComponent.vue @@ -11,16 +11,19 @@ export default { auth: false } }, created() { - let authCode = this.$route.query.code; + try { + let authCode = this.$route.query.code; + console.log('Auth Code:', authCode); - LogIn(authCode).then(data => { - console.log(data); - // Обработка данных, возвращённых LogIn - this.auth = true; // Обновляем состояние, основываясь на данных - }).catch(error => { - console.log(error) -}) - console.log(authCode) + if (authCode) { + const data = LogIn(authCode); + console.log('Auth Data:', data); + } else { + console.log('Auth Code отсутствует'); + } + } catch (error) { + console.error('Ошибка при аутентификации:', error); + } } } @@ -48,16 +51,17 @@ export default {