all repos — stealth-developers @ 124009fe8d16aefd3401cb00740df5e6d26d6a44

apps/api/src/routes/sync.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
import { editActor, getActorByPin } from "@stealth-developers/db";
import Elysia, { t } from "elysia";

export const syncRoutes = new Elysia({ prefix: "/sync" }).post(
	"/verify",
	async ({ body, set }) => {
		const user = await getActorByPin(body.pin);
		if (!user) {
			set.status = 404;
			return { error: "Pin not found" };
		}

		const expiryDate = new Date(user.pinExpiresIn!);
		if (expiryDate < new Date()) {
			set.status = 401;
			return { error: "Pin expired" };
		}

		await editActor(user.id, {
			robloxId: body.roblox_user_id,
			pin: null,
			pinExpiresIn: null,
		});

		return { success: true };
	},
	{
		body: t.Object({
			pin: t.String(),
			roblox_user_id: t.String(),
		}),
	},
);