add types and fix loading

This commit is contained in:
Fran Jurmanović
2025-02-12 00:48:43 +01:00
parent e9487ba38f
commit d29165261c
22 changed files with 410 additions and 146 deletions

View File

@@ -1,9 +1,10 @@
import fetchAPI, { fetchAPIEvent } from '$api/apiService';
import { authStore } from '$stores/authStore';
import { redisSessionManager } from '$stores/redisSessionManager';
import type { RequestEvent } from '@sveltejs/kit';
import { v4 as uuidv4 } from 'uuid';
export const login = async (event: object, username: string, password: string) => {
export const login = async (event: RequestEvent, username: string, password: string) => {
const token = btoa(`${username}:${password}`);
await redisSessionManager.createSession(event.cookies, { token }, uuidv4());
if (!(await checkAuth(event))) {
@@ -15,11 +16,11 @@ export const login = async (event: object, username: string, password: string) =
return true;
};
export const logout = (event) => {
export const logout = (event: RequestEvent) => {
return redisSessionManager.deleteCookie(event.cookies);
};
export const checkAuth = async (event: object) => {
export const checkAuth = async (event: RequestEvent) => {
try {
await fetchAPIEvent(event, '/api');
return true;