aboutsummaryrefslogtreecommitdiffstats
path: root/backend/src/routes/user.ts
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-06-30 00:58:56 -0700
committerPinapelz <yukais@pinapelz.com>2025-06-30 00:58:56 -0700
commitfae6914acace1a3b470f9d243fe8a2ba0f141388 (patch)
treecc2ac24b97b464189c220d6c5abe7d48e92f28aa /backend/src/routes/user.ts
parent722df5105c098f404e09e884a817acf92d939648 (diff)
add basic batch manual score upload route
Diffstat (limited to 'backend/src/routes/user.ts')
-rw-r--r--backend/src/routes/user.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/backend/src/routes/user.ts b/backend/src/routes/user.ts
new file mode 100644
index 0000000..a03ece0
--- /dev/null
+++ b/backend/src/routes/user.ts
@@ -0,0 +1,41 @@
+// Routes about self (or users in general)
+import express from 'express';
+import { prisma } from '../config/db';
+
+export const handleMeRoute = async (req: express.Request, res: express.Response) => {
+ try {
+ const user = (req as any).user;
+ res.json(user);
+ } catch (error) {
+ console.error('Me endpoint error:', error);
+ res.status(500).json({ error: 'Internal server error' });
+ }
+}
+
+export const handleGetCurrentSession = async (req: express.Request, res: express.Response) => {
+ try {
+ if (!req.session.userId) {
+ return res.json({ authenticated: false });
+ }
+
+ const user = await prisma.user.findUnique({
+ where: { id: req.session.userId },
+ select: { id: true, username: true, email: true }
+ });
+
+ if (!user) {
+ req.session.destroy((err) => {
+ if (err) console.error('Session destroy error:', err);
+ });
+ return res.json({ authenticated: false });
+ }
+
+ res.json({
+ authenticated: true,
+ user
+ });
+ } catch (error) {
+ console.error('Session check error:', error);
+ res.status(500).json({ error: 'Internal server error' });
+ }
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage