Skip to content

Commit 04cc13f

Browse files
committed
fix: ensure new session is created when no session
Signed-off-by: Alexander Alemayhu <alexander@alemayhu.com>
1 parent 8884fcf commit 04cc13f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/routes/ki/KiRouter.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,25 @@ const KiRouter = () => {
303303
return false;
304304
}
305305

306-
const userId = user.owner; // Assuming token contains userId
307-
const userSession = await sessionRepository.getSession(userId); // Ensure session is typed
306+
const userId = user.owner;
307+
let userSession = await sessionRepository.getSession(userId);
308+
309+
// Create new session if none exists
310+
if (!userSession || !userSession.data) {
311+
const w = new Workspace(true, 'fs');
312+
await sessionRepository.createSession(userId, {
313+
uploadedFiles: [],
314+
deckInfo: [],
315+
workspace: w,
316+
});
317+
userSession = await sessionRepository.getSession(userId);
318+
}
319+
308320
if (!userSession || !userSession.data) {
309-
// Check if userSession.data is defined
310321
return res.status(403).json({ error: 'Session expired' });
311322
}
312323

313-
const files = req.files as UploadedFile[]; // Ensure files are typed
324+
const files = req.files as UploadedFile[];
314325
console.log('[UPLOAD] Request received:', req.body);
315326
console.log('[UPLOAD] Starting file upload process');
316327
try {

0 commit comments

Comments
 (0)