[FIX] Use New Cairo System
This commit is contained in:
parent
6eed3fd694
commit
8c7e41b21b
4 changed files with 12 additions and 9 deletions
|
@ -4,12 +4,12 @@ import bearerTokenMiddleware from "express-bearer-token";
|
|||
import { ERR, VERB } from "../../util/logging.js";
|
||||
|
||||
// Constants
|
||||
const { MCL_CAIRO_URL } = process.env;
|
||||
const { MCL_CAIRO_URL, MCL_CAIRO_PROJECT } = process.env;
|
||||
const cairoAuthMiddleware = Router();
|
||||
|
||||
const cairoAuthenticate = async (token) => {
|
||||
const config = { headers: { Authorization: `Bearer ${token}` } };
|
||||
return fetch(`${MCL_CAIRO_URL}/api/user/info`, config).then(async (res) => {
|
||||
return fetch(`${MCL_CAIRO_URL}/api/${MCL_CAIRO_PROJECT}/auth/credentials`, config).then(async (res) => {
|
||||
if (res.status >= 300) {
|
||||
const errorMessage = await res
|
||||
.json()
|
||||
|
@ -30,9 +30,9 @@ const cairoAuthHandler = (req, res, next) => {
|
|||
cairoAuthenticate(req.token)
|
||||
.then((authData) => {
|
||||
console.log(authData);
|
||||
if (!authData.id)
|
||||
throw Error(`Cairo didn't return the expected data! ${authData.id}`);
|
||||
req.cairoId = authData.id;
|
||||
if (!authData?.user?.id)
|
||||
throw Error(`Cairo didn't return the expected data! ${authData?.user?.id}`);
|
||||
req.cairoId = authData?.user?.id;
|
||||
})
|
||||
.then(() => next())
|
||||
.catch((err) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue