mirror of
https://github.com/yawaflua/LuckyDiamond.git
synced 2025-12-10 12:19:31 +02:00
Add auth provider
This commit is contained in:
@@ -1,12 +1,21 @@
|
|||||||
import { Post } from '../rest/RestMethods.js';
|
import { Post } from '../rest/RestMethods.js';
|
||||||
import { BackendApiUrl } from '@/properties/Сonfig.js';
|
import { BackendApiUrl } from '@/properties/Сonfig.js';
|
||||||
|
|
||||||
export function
|
// export function
|
||||||
LogIn(authCode) {
|
// LogIn(authCode) {
|
||||||
return Post(BackendApiUrl + "/LogIn", { code: authCode }).then((data) => {
|
// return Post(BackendApiUrl + "/LogIn", { code: authCode }).then((data) => {
|
||||||
console.log(data);
|
// console.log(data);
|
||||||
return data;
|
// return data;
|
||||||
}).catch(error => {
|
// }).catch(error => {
|
||||||
console.log(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,41 @@
|
|||||||
export async function Post(url = "", data = {}) {
|
export async function Post(url = "", data = {}) {
|
||||||
|
|
||||||
// Default options are marked with *
|
// Default options are marked with *
|
||||||
try {
|
// try {
|
||||||
const response = await fetch(url, {
|
// const response = await fetch(url, {
|
||||||
method: "POST",
|
// method: "POST",
|
||||||
headers: {
|
// headers: {
|
||||||
"Content-Type": "application/json",
|
// "Content-Type": "application/json",
|
||||||
},
|
// },
|
||||||
redirect: "follow",
|
// redirect: "follow",
|
||||||
referrerPolicy: "no-referrer",
|
// referrerPolicy: "no-referrer",
|
||||||
body: JSON.stringify(data),
|
// body: JSON.stringify(data),
|
||||||
});
|
// });
|
||||||
if (!response.ok) {
|
// if (!response.ok) {
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
// console.log("Fetch error:", response.status);
|
||||||
}
|
// }
|
||||||
return await response.json();
|
// return await response.json();
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
console.log("Fetch error:", error);
|
// console.log("Fetch error:", error);
|
||||||
throw error; // Re-throw the error so it can be caught by the calling function
|
// }
|
||||||
}
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -11,16 +11,19 @@ export default {
|
|||||||
auth: false
|
auth: false
|
||||||
}
|
}
|
||||||
}, created() {
|
}, created() {
|
||||||
|
try {
|
||||||
let authCode = this.$route.query.code;
|
let authCode = this.$route.query.code;
|
||||||
|
console.log('Auth Code:', authCode);
|
||||||
|
|
||||||
LogIn(authCode).then(data => {
|
if (authCode) {
|
||||||
console.log(data);
|
const data = LogIn(authCode);
|
||||||
// Обработка данных, возвращённых LogIn
|
console.log('Auth Data:', data);
|
||||||
this.auth = true; // Обновляем состояние, основываясь на данных
|
} else {
|
||||||
}).catch(error => {
|
console.log('Auth Code отсутствует');
|
||||||
console.log(error)
|
}
|
||||||
})
|
} catch (error) {
|
||||||
console.log(authCode)
|
console.error('Ошибка при аутентификации:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -48,16 +51,17 @@ export default {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="header__auth--discord">
|
<div class="header__auth--discord">
|
||||||
<div v-if="auth" class="header__card--discord">
|
<!-- <div v-if="auth" class="header__card--discord">
|
||||||
<div class="discord__card--name">
|
<div class="discord__card--name">
|
||||||
<h2>Artemka</h2>
|
<h2>Artemka</h2>
|
||||||
<a href="#" @click="auth = false">Выход<span><img src="../assets/icons-header/exit-icon.png"></span></a>
|
<a href="#" @click="auth = false">Выход<span><img src="../assets/icons-header/exit-icon.png"></span></a>
|
||||||
</div>
|
</div>
|
||||||
<img src="../assets/icons-test/person-icon.svg" alt="test-ico">
|
<img src="../assets/icons-test/person-icon.svg" alt="test-ico">
|
||||||
</div>
|
</div> -->
|
||||||
<div v-else class="header__card--auth">
|
<!-- <div v-else class="header__card--auth"> -->
|
||||||
|
<div class="header__card--auth">
|
||||||
<div class="auth__card--content">
|
<div class="auth__card--content">
|
||||||
<a href="#" @click="auth = true"><span><img width="30" height="30" src="../assets/icons-header/discord-icon.svg"></span>Вход</a>
|
<a href="https://discord.com/api/oauth2/authorize?client_id=1148644854797176932&redirect_uri=https%3A%2F%2Flucky-diamond.vercel.app%2F&response_type=code&scope=identify" @click="auth = true"><span><img width="30" height="30" src="../assets/icons-header/discord-icon.svg"></span>Вход</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
// export const BackendApiUrl = 'https://spsystemcore20231122004605.azurewebsites.net';
|
// export const BackendApiUrl = 'https://spsystemcore20231122004605.azurewebsites.net';
|
||||||
export const BackendApiUrl = 'https://localhost:7062';
|
export const BackendApiUrl = 'https://localhost:7062/api';
|
||||||
Reference in New Issue
Block a user