migrate to nextjs

This commit is contained in:
Fran Jurmanović
2025-08-27 20:38:19 +02:00
parent 965e13a0bf
commit b269144ee7
120 changed files with 10393 additions and 8526 deletions

View File

@@ -0,0 +1,30 @@
import { User } from '@/lib/types';
import { fetchServerAPI } from './base';
const BASE_URL = process.env.API_BASE_URL || 'http://localhost:8080';
const authRoute = '/auth';
export async function loginUser(username: string, password: string) {
const response = await fetch(`${BASE_URL}${authRoute}/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ username, password })
});
if (!response.ok) {
throw new Error(`Login failed: ${response.statusText} - ${BASE_URL}${authRoute}/login`);
}
const { token } = await response.json();
const userResponse = await getCurrentUser(token);
return { token, user: userResponse };
}
export async function getCurrentUser(token: string) {
return fetchServerAPI<User>(`${authRoute}/me`, token);
}