[FIX] Use New Cairo System
This commit is contained in:
parent
6eed3fd694
commit
8c7e41b21b
4 changed files with 12 additions and 9 deletions
|
@ -1,7 +1,7 @@
|
|||
CREATE SEQUENCE servers_id_seq;
|
||||
CREATE TABLE servers (
|
||||
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,
|
||||
name varchar(255) DEFAULT NULL,
|
||||
version varchar(63) DEFAULT 'latest',
|
||||
|
|
|
@ -2,11 +2,14 @@ import { Router } from "express";
|
|||
import cairoAuthMiddleware from "./middlewares/auth-middleware.js";
|
||||
const router = Router();
|
||||
|
||||
const cairoProjectId = process.env.MCL_CAIRO_PROJECT;
|
||||
if(!cairoProjectId) throw Error("Cairo Project Required!");
|
||||
|
||||
const ok = (_r, res) => res.sendStatus(200);
|
||||
|
||||
function cairoRedirect(req, res) {
|
||||
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}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
|
||||
const tokenStorageName = "cairoAuthToken";
|
||||
const tokenQuery = "cairoAuthToken";
|
||||
const tokenStorageName = "cairoUserToken";
|
||||
const tokenQuery = "cairoUserToken";
|
||||
|
||||
const verifyAuth = (authToken) =>
|
||||
fetch("/api/auth/verify", {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue