1 import { server } from '../../lib/server';
2 import { Static, Type } from '@sinclair/typebox';
3 import { prisma } from '../../lib/db';
4 import { NotFoundError } from '../../lib/http-errors';
5 import { v4 as uuid } from 'uuid';
6 import {Player} from '@prisma/client';
8 const LoginInput = Type.Object({
10 username: Type.String(),
11 password: Type.String()
15 type LoginInputType = Static<typeof LoginInput>;
17 export type LoginOutputType = {
22 export const login = server.post<LoginInputType, any>('/v1/accounts/auth', {
25 const {username, password} = req.body;
26 const player = await prisma.player.findUnique({
32 if(!player || password !== player.password) {
33 throw new NotFoundError('Invalid user credentials');
36 const token = await prisma.authToken.upsert({