add types and fix loading
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user