Spaces:
Build error
Build error
| import { sessionRepository } from '@core/storage/repositories/sessions.js'; | |
| import { userRepository } from '@core/storage/repositories/users.js'; | |
| export interface SessionUser { | |
| id: string; | |
| username: string; | |
| isAdmin: boolean; | |
| isBanned: boolean; | |
| } | |
| export async function getSessionUser(sessionId: string): Promise<SessionUser | null> { | |
| const session = await sessionRepository.findValidSession(sessionId); | |
| if (!session) return null; | |
| const user = await userRepository.findById(session.userId); | |
| if (!user || user.isBanned) return null; | |
| return { | |
| id: user.id, | |
| username: user.username, | |
| isAdmin: user.isAdmin, | |
| isBanned: user.isBanned, | |
| }; | |
| } | |
| export async function createUserSession(userId: string): Promise<string> { | |
| const session = await sessionRepository.createSession(userId); | |
| return session.id; | |
| } | |
| export async function destroySession(sessionId: string): Promise<void> { | |
| await sessionRepository.deleteSession(sessionId); | |
| } | |
| export async function destroyAllUserSessions(userId: string): Promise<void> { | |
| await sessionRepository.deleteUserSessions(userId); | |
| } | |
| export async function refreshSession(sessionId: string): Promise<boolean> { | |
| const session = await sessionRepository.findValidSession(sessionId); | |
| if (!session) return false; | |
| const newExpiresAt = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(); | |
| await sessionRepository.updateSession(sessionId, { expiresAt: newExpiresAt }); | |
| return true; | |
| } |