mirror of
https://github.com/yawaflua/LuckyDiamond.git
synced 2025-12-10 04:09:29 +02:00
Add auth provider
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
// 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));
|
||||
|
||||
|
||||
}
|
||||
@@ -11,16 +11,19 @@ export default {
|
||||
auth: false
|
||||
}
|
||||
}, created() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -48,16 +51,17 @@ export default {
|
||||
</div>
|
||||
</div>
|
||||
<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">
|
||||
<h2>Artemka</h2>
|
||||
<a href="#" @click="auth = false">Выход<span><img src="../assets/icons-header/exit-icon.png"></span></a>
|
||||
</div>
|
||||
<img src="../assets/icons-test/person-icon.svg" alt="test-ico">
|
||||
</div>
|
||||
<div v-else class="header__card--auth">
|
||||
</div> -->
|
||||
<!-- <div v-else class="header__card--auth"> -->
|
||||
<div class="header__card--auth">
|
||||
<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>
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
// 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