feat: creates backend for the project

This commit is contained in:
vakabunga
2026-03-02 00:32:37 +03:00
parent 9d12702688
commit 4d67636633
24 changed files with 1735 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import { v4 as uuidv4 } from 'uuid';
import { pool } from '../db/pool';
import { config } from '../config';
import type { LoginRequest, MeResponse } from '@family-budget/shared';
export async function login(
body: LoginRequest,
): Promise<{ sessionId: string } | null> {
if (body.login !== config.appUserLogin || body.password !== config.appUserPassword) {
return null;
}
const sid = uuidv4();
await pool.query(
'INSERT INTO sessions (id) VALUES ($1)',
[sid],
);
return { sessionId: sid };
}
export async function logout(sessionId: string): Promise<void> {
await pool.query(
'UPDATE sessions SET is_active = FALSE WHERE id = $1',
[sessionId],
);
}
export async function me(sessionId: string): Promise<MeResponse> {
return { login: config.appUserLogin };
}