import Mail from "../../models/mail";
import { GetClientApiAuthMiddleware } from "../middlewares/client";
import Stacker from "../middlewares/stacker";
import { Request, Response } from "express";

export default Stacker(GetClientApiAuthMiddleware(), async (req: Request, res) => {
   let mails = await Promise.all(
      req.user.mails.map((id) => Mail.findById(id))
   );

   let mail = mails.find((e) => e.primary) || mails[0];

   res.json({
      user_id: req.user.uid,
      id: req.user.uid,
      ID: req.user.uid,
      sub: req.user.uid,
      email: mail.mail,
      username: req.user.username,
      displayName: req.user.name,
      "display-name": req.user.name,
      displayNameClaim: req.user.name,
      name: req.user.name,
   });
})
