[FIX] Use New Cairo System
Some checks failed
Deploy USW-MC / deploy-edge (push) Failing after 2s
Deploy Edge Proxy / deploy-edge (push) Failing after 2s
S3 Repo Backup / s3-repo-backup (push) Failing after 5s

This commit is contained in:
Dunemask 2024-08-24 16:41:52 -06:00
parent 6eed3fd694
commit 8c7e41b21b
4 changed files with 12 additions and 9 deletions

View file

@ -1,7 +1,7 @@
CREATE SEQUENCE servers_id_seq; CREATE SEQUENCE servers_id_seq;
CREATE TABLE servers ( CREATE TABLE servers (
id bigint NOT NULL DEFAULT nextval('servers_id_seq') PRIMARY KEY, id bigint NOT NULL DEFAULT nextval('servers_id_seq') PRIMARY KEY,
owner_cairo_id bigint, owner_cairo_id varchar(63),
host varchar(255) DEFAULT NULL, host varchar(255) DEFAULT NULL,
name varchar(255) DEFAULT NULL, name varchar(255) DEFAULT NULL,
version varchar(63) DEFAULT 'latest', version varchar(63) DEFAULT 'latest',

View file

@ -2,11 +2,14 @@ import { Router } from "express";
import cairoAuthMiddleware from "./middlewares/auth-middleware.js"; import cairoAuthMiddleware from "./middlewares/auth-middleware.js";
const router = Router(); const router = Router();
const cairoProjectId = process.env.MCL_CAIRO_PROJECT;
if(!cairoProjectId) throw Error("Cairo Project Required!");
const ok = (_r, res) => res.sendStatus(200); const ok = (_r, res) => res.sendStatus(200);
function cairoRedirect(req, res) { function cairoRedirect(req, res) {
res.redirect( res.redirect(
`${process.env.MCL_CAIRO_URL}/cairo/auth?redirectUri=${req.query.redirectUri}`, `${process.env.MCL_CAIRO_URL}/cairo/authenticate?redirectUri=${req.query.redirectUri}&projectId=${cairoProjectId}`,
); );
} }

View file

@ -4,12 +4,12 @@ import bearerTokenMiddleware from "express-bearer-token";
import { ERR, VERB } from "../../util/logging.js"; import { ERR, VERB } from "../../util/logging.js";
// Constants // Constants
const { MCL_CAIRO_URL } = process.env; const { MCL_CAIRO_URL, MCL_CAIRO_PROJECT } = process.env;
const cairoAuthMiddleware = Router(); const cairoAuthMiddleware = Router();
const cairoAuthenticate = async (token) => { const cairoAuthenticate = async (token) => {
const config = { headers: { Authorization: `Bearer ${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) { if (res.status >= 300) {
const errorMessage = await res const errorMessage = await res
.json() .json()
@ -30,9 +30,9 @@ const cairoAuthHandler = (req, res, next) => {
cairoAuthenticate(req.token) cairoAuthenticate(req.token)
.then((authData) => { .then((authData) => {
console.log(authData); console.log(authData);
if (!authData.id) if (!authData?.user?.id)
throw Error(`Cairo didn't return the expected data! ${authData.id}`); throw Error(`Cairo didn't return the expected data! ${authData?.user?.id}`);
req.cairoId = authData.id; req.cairoId = authData?.user?.id;
}) })
.then(() => next()) .then(() => next())
.catch((err) => { .catch((err) => {

View file

@ -1,8 +1,8 @@
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { useSearchParams } from "react-router-dom"; import { useSearchParams } from "react-router-dom";
const tokenStorageName = "cairoAuthToken"; const tokenStorageName = "cairoUserToken";
const tokenQuery = "cairoAuthToken"; const tokenQuery = "cairoUserToken";
const verifyAuth = (authToken) => const verifyAuth = (authToken) =>
fetch("/api/auth/verify", { fetch("/api/auth/verify", {