mirror of
https://github.com/KeyZox71/knl_meowscendence.git
synced 2025-12-31 21:56:41 +01:00
「🔨」 fix(front): added exception catching
This commit is contained in:
@ -59,9 +59,9 @@ const deleteFriends = database.prepare('DELETE FROM friends WHERE username = ?;'
|
|||||||
export default async function(fastify, options) {
|
export default async function(fastify, options) {
|
||||||
|
|
||||||
fastify.register(cors, {
|
fastify.register(cors, {
|
||||||
origin: process.ENV.CORS_ORIGIN || 'http://localhost:5173',
|
origin: process.env.CORS_ORIGIN || 'http://localhost:5173',
|
||||||
credentials: true,
|
credentials: true,
|
||||||
methods: [ "GET", "POST", "DELETE", "OPTIONS" ]
|
methods: [ "GET", "POST", "PATCH", "DELETE", "OPTIONS" ]
|
||||||
});
|
});
|
||||||
|
|
||||||
fastify.register(fastifyJWT, {
|
fastify.register(fastifyJWT, {
|
||||||
|
|||||||
@ -40,13 +40,13 @@ export default class extends Aview {
|
|||||||
async function getMainHTML() {
|
async function getMainHTML() {
|
||||||
if (!(await isLogged()))
|
if (!(await isLogged()))
|
||||||
{
|
{
|
||||||
document.getElementById("menu-bottom-div").classList.add("hidden");
|
document.getElementById("menu-bottom-div")?.classList.add("hidden");
|
||||||
return `
|
return `
|
||||||
<a class="menu-default-button inline-flex items-center justify-center" href="/login" data-link>login</a>
|
<a class="menu-default-button inline-flex items-center justify-center" href="/login" data-link>login</a>
|
||||||
<a class="menu-default-button inline-flex items-center justify-center" href="/register" data-link>register</a>
|
<a class="menu-default-button inline-flex items-center justify-center" href="/register" data-link>register</a>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
document.getElementById("menu-bottom-div").classList.remove("hidden");
|
document.getElementById("menu-bottom-div")?.classList.remove("hidden");
|
||||||
|
|
||||||
uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2];
|
uuid = document.cookie.match(new RegExp('(^| )' + "uuid" + '=([^;]+)'))[2];
|
||||||
const userdata_req = await fetch(`http://localhost:3002/users/${uuid}`, {
|
const userdata_req = await fetch(`http://localhost:3002/users/${uuid}`, {
|
||||||
@ -71,7 +71,7 @@ export default class extends Aview {
|
|||||||
|
|
||||||
document.getElementById("profile-items").innerHTML = await getMainHTML();
|
document.getElementById("profile-items").innerHTML = await getMainHTML();
|
||||||
|
|
||||||
document.getElementById("menu-logout").addEventListener("click", async () => {
|
document.getElementById("menu-logout")?.addEventListener("click", async () => {
|
||||||
let req = await fetch("http://localhost:3001/logout", {
|
let req = await fetch("http://localhost:3001/logout", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
|
|||||||
@ -5,8 +5,7 @@ import { isLogged, navigationManager } from "../main.ts"
|
|||||||
|
|
||||||
export default class extends Aview {
|
export default class extends Aview {
|
||||||
|
|
||||||
constructor()
|
constructor() {
|
||||||
{
|
|
||||||
super();
|
super();
|
||||||
this.setTitle("register");
|
this.setTitle("register");
|
||||||
setOnekoState("default");
|
setOnekoState("default");
|
||||||
@ -53,7 +52,7 @@ export default class extends Aview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run() {
|
async run() {
|
||||||
dragElement(document.getElementById("window"));
|
dragElement(document.getElementById("window"));
|
||||||
const login = async () => {
|
const login = async () => {
|
||||||
const username = (document.getElementById("username") as HTMLInputElement).value;
|
const username = (document.getElementById("username") as HTMLInputElement).value;
|
||||||
const password = (document.getElementById("password") as HTMLInputElement).value;
|
const password = (document.getElementById("password") as HTMLInputElement).value;
|
||||||
@ -67,34 +66,34 @@ export default class extends Aview {
|
|||||||
});
|
});
|
||||||
const data = await data_req.json();
|
const data = await data_req.json();
|
||||||
|
|
||||||
if (data_req.status === 200)
|
if (data_req.status === 200) {
|
||||||
{
|
|
||||||
let uuid_req = await fetch("http://localhost:3001/me", {
|
let uuid_req = await fetch("http://localhost:3001/me", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
});
|
});
|
||||||
let uuid = await uuid_req.json();
|
let uuid = await uuid_req.json();
|
||||||
document.cookie = `uuid=${uuid.user};max-ages=${60*60*24*7}`;
|
document.cookie = `uuid=${uuid.user};max-ages=${60 * 60 * 24 * 7}`;
|
||||||
console.log(document.cookie);
|
console.log(document.cookie);
|
||||||
isLogged();
|
isLogged();
|
||||||
navigationManager("/");
|
navigationManager("/");
|
||||||
}
|
}
|
||||||
else if (data_req.status === 400)
|
else if (data_req.status === 400) {
|
||||||
{
|
if (document.getElementById("login-error-message")) {
|
||||||
document.getElementById("login-error-message").innerHTML = "error: " + data.error;
|
document.getElementById("login-error-message").innerHTML = "error: " + data.error;
|
||||||
document.getElementById("login-error-message").classList.remove("hidden");
|
document.getElementById("login-error-message")?.classList.remove("hidden");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
throw new Error("invalid response");
|
throw new Error("invalid response");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (error)
|
catch (error) {
|
||||||
{
|
|
||||||
console.error(error);
|
console.error(error);
|
||||||
document.getElementById("login-error-message").innerHTML = "error: server error, try again later...";
|
if (document.getElementById("login-error-message")) {
|
||||||
document.getElementById("login-error-message").classList.remove("hidden");
|
document.getElementById("login-error-message").innerHTML = "error: server error, try again later...";
|
||||||
|
document.getElementById("login-error-message")?.classList.remove("hidden");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user