const { getPassportStatus } = require('@abtnode/auth/lib/auth');

module.exports = {
  init(server, node, opts) {
    server.get(`${opts.prefix}/api/passport/status`, async (req, res) => {
      const { vcId, userDid, locale } = req.query;
      const teamDid = req.headers['x-blocklet-did'];

      if (teamDid !== req.query.teamDid) {
        throw new Error('teamDid is invalid');
      }

      const status = await getPassportStatus({ node, teamDid, userDid, vcId, locale });

      res.json(status);
    });
  },
};
