feat: Remove shared/
This commit is contained in:
18
backend/src/utils/user.ts
Normal file
18
backend/src/utils/user.ts
Normal 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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user