feat: Remove shared/

This commit is contained in:
Alexander Polynomdivision
2018-09-29 15:06:14 +02:00
parent 65070b1f5b
commit fdaa9cb8f3
8 changed files with 89 additions and 80 deletions

18
backend/src/utils/user.ts Normal file
View File

@@ -0,0 +1,18 @@
import { Db } from "mongodb";
import { IUser } from "../models/user";
export async function userFromSession(token: string, db: Db): Promise<IUser> {
// Get the username
const session = await db.collection("sessions").findOne({ token, });
if (session) {
const user = await db.collection("users").findOne({ username: session.username });
if (user) {
return user;
} else {
throw new Error("Failed to find user");
}
} else {
throw new Error("Failed to find session");
}
}