yandex auth, bug fixes

This commit is contained in:
Ivan
2024-01-29 21:31:16 +03:00
parent 0b1d5e8b79
commit 24d47644d4
5 changed files with 188 additions and 10 deletions

View File

@@ -5,10 +5,16 @@
<meta charSet="utf-8" />
<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, shrink-to-fit=no, viewport-fit=cover'>
<meta http-equiv='X-UA-Compatible' content='ie=edge'>
<link rel="stylesheet" href="../styles/main.css">
<style>
html,
body {
background: #eee;
height: 100%;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
</style>
<script src="https://yastatic.net/s3/passport-sdk/autofill/v1/sdk-suggest-token-with-polyfills-latest.js"></script>
@@ -21,7 +27,57 @@
"kek": true,
});
};
function getCookie(name) {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
if (cookie.startsWith(name + "=")) {
return cookie.substring(name.length + 1);
}
}
return null;
}
document.addEventListener('DOMContentLoaded', async function () {
const fragment = window.location.hash.substring(1);
if (fragment.includes('access_token')) {
const accessToken = fragment.split('&')[0].split('=')[1];
console.log(accessToken);
const response = await fetch('{{API_SERVER}}/yandexauth?token=' + accessToken, {
method: "POST",
headers: {
Authorization: getCookie("token"),
"Content-Type": "application/json"
}
});
if (response.status === 200) {
const data = await response.json();
const token = data.token;
document.cookie = "token=" + token;
window.location.href = "/projects";
} else if (response.status === 401) {
alert("Сначала нужно привязать аккаунт Яндекса в настройках");
location.href= '/';
} else if (response.status === 403) {
alert("Неверный токен");
location.href= '/';
} else {
alert("Ошибка авторизации");
location.href= '/';
}
}
});
</script>
<video style="border-radius: 13px; width: 300px;" src="../img/krbl-square.mp4" autoplay loop muted playsinline preload="auto"></video>
<h2>Пожалуйста, подождите...</h2>
</body>
</html>