mirror of
https://github.com/KeyZox71/knl_meowscendence.git
synced 2025-10-14 10:54:45 +02:00
「🏗️」 wip: tmp commit, will be overriden later, can be ignored
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import fastifyJWT from '@fastify/jwt';
|
||||
import fastifyCookie from '@fastify/cookie';
|
||||
import cors from '@fastify/cors'
|
||||
|
||||
import { register } from './register.js';
|
||||
import { login } from './login.js';
|
||||
@ -22,6 +23,12 @@ authDB.prepareDB();
|
||||
*/
|
||||
export default async function(fastify, options) {
|
||||
|
||||
fastify.register(cors, {
|
||||
origin: "http://localhost:5173",
|
||||
credentials: true,
|
||||
methods: [ "GET", "POST", "DELETE", "OPTIONS" ]
|
||||
});
|
||||
|
||||
fastify.register(fastifyJWT, {
|
||||
secret: process.env.JWT_SECRET || '123456789101112131415161718192021',
|
||||
cookie: {
|
||||
|
@ -37,11 +37,7 @@ export default class extends Aview {
|
||||
credentials: "include",
|
||||
body: JSON.stringify({ user: username, password: password }),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
/*const data = { "error": "invalid password or smth" };
|
||||
const response = { status: 400};*/
|
||||
|
||||
|
||||
if (response.status === 200)
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ export default class extends Aview {
|
||||
<input type="text" id="username" placeholder="username" class="bg-white text-neutral-900 border rounded-md w-full px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"></input>
|
||||
<input type="password" id="password" placeholder="password" class="bg-white text-neutral-900 border w-full px-4 py-2 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"></input>
|
||||
|
||||
<button type="submit" class="bg-blue-600 text-white hover:bg-blue-500 w-full py-2 rounded-md transition-colors">register</button>
|
||||
<button id="register-button" type="submit" class="bg-blue-600 text-white hover:bg-blue-500 w-full py-2 rounded-md transition-colors">register</button>
|
||||
|
||||
<a class="text-gray-400 dark:text-gray-600 underline" href="/login" data-link>
|
||||
i already have an account
|
||||
@ -24,4 +24,40 @@ export default class extends Aview {
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
async run() {
|
||||
const login = async () => {
|
||||
const username = (document.getElementById("username") as HTMLInputElement).value;
|
||||
const password = (document.getElementById("password") as HTMLInputElement).value;
|
||||
|
||||
try {
|
||||
const response = await fetch("http://localhost:3001/register", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", },
|
||||
credentials: "include",
|
||||
body: JSON.stringify({ user: username, password: password }),
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
if (response.status === 200)
|
||||
{
|
||||
navigationManager("/");
|
||||
}
|
||||
else if (response.status === 400)
|
||||
{
|
||||
document.getElementById("login-error-message").innerHTML = "error: " + data.error;
|
||||
document.getElementById("login-error-message").classList.remove("hidden");
|
||||
}
|
||||
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
console.log(error);
|
||||
document.getElementById("login-error-message").innerHTML = "error: server error, try again later...";
|
||||
document.getElementById("login-error-message").classList.remove("hidden");
|
||||
}
|
||||
};
|
||||
|
||||
document.getElementById("register-button")?.addEventListener("click", login);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user