1
0
Fork 0
llama-bot-web-interface/functions/src/routes/dataRoutes.ts
developomp 695f75d363 backend structure update
- removed unnecessry data from express user
- changed database arguments and return types
- made `/api/user-data` get data from db instead of express user
2022-02-27 10:44:42 +09:00

30 lines
743 B
TypeScript

/*
* Handle firestore read/writes related to discord bot
*/
import { Express, Request, Response, NextFunction } from "express"
import database from "../API/database"
import config from "../config.json"
const checkIfLoggedIn = (req: Request, res: Response, next: NextFunction) => {
if (req.isAuthenticated()) return next()
res.status(401).send("Not authenticated")
}
export default (app: Express): void => {
/**
* Get user data from google firebase firestore
*/
app.get(
config.pathPrefix + "/user-data",
checkIfLoggedIn,
async (req, res) => {
res.setHeader("Cache-Control", "private")
req.user
? res.status(200).send(await database.getUser(req.user.id))
: res.status(500).send("Failed to get user")
}
)
}