Skip to content

Commit

Permalink
fix: cors
Browse files Browse the repository at this point in the history
  • Loading branch information
gllm-dev committed Oct 18, 2024
1 parent 87cb391 commit c65e491
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 21 deletions.
2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
"@openfort/openfort-node": "^0.6.66",
"@types/express": "^5.0.0",
"@types/node": "^22.7.6",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.21.1"
},
"devDependencies": {
"@types/cors": "^2.8.17",
"ts-node-dev": "^2.0.0",
"typescript": "^5.6.3"
}
Expand Down
4 changes: 0 additions & 4 deletions backend/src/api/create-encryption-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ export async function createEncryptionSession(
req: Request,
res: Response
) {
console.log('createEncryptionSession');
try {
console.log(process.env.SHIELD_API_KEY);
console.log(process.env.SHIELD_SECRET_KEY);
console.log(process.env.SHIELD_ENCRYPTION_SHARE);
const session = await openfort.registerRecoverySession(process.env.SHIELD_API_KEY!, process.env.SHIELD_SECRET_KEY!, process.env.SHIELD_ENCRYPTION_SHARE!)
res.status(200).send({
session: session,
Expand Down
4 changes: 2 additions & 2 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import dotenv from 'dotenv';
dotenv.config();

import express, { Request, Response } from 'express';
import {createEncryptionSession} from "./api/create-encryption-session";
import {createSession} from "./api/create-session";
import {collect} from "./api/collect";
import {revokeSession} from "./api/revoke-session";

import cors from 'cors';

// Create an instance of Express
const app = express();
app.use(express.json());
app.use(cors());

// Define the port number
const PORT = process.env.SERVER_PORT || 3005;
Expand Down
22 changes: 21 additions & 1 deletion backend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
dependencies:
"@types/node" "*"

"@types/cors@^2.8.17":
version "2.8.17"
resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.17.tgz#5d718a5e494a8166f569d986794e49c48b216b2b"
integrity sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==
dependencies:
"@types/node" "*"

"@types/express-serve-static-core@^5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-5.0.0.tgz#91f06cda1049e8f17eeab364798ed79c97488a1c"
Expand Down Expand Up @@ -333,6 +340,14 @@ [email protected]:
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.7.1.tgz#2f73c42142d5d5cf71310a74fc4ae61670e5dbc9"
integrity sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==

cors@^2.8.5:
version "2.8.5"
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
dependencies:
object-assign "^4"
vary "^1"

create-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
Expand Down Expand Up @@ -771,6 +786,11 @@ normalize-path@^3.0.0, normalize-path@~3.0.0:
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==

object-assign@^4:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==

object-inspect@^1.13.1:
version "1.13.2"
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.13.2.tgz#dea0088467fb991e67af4058147a24824a3043ff"
Expand Down Expand Up @@ -1105,7 +1125,7 @@ v8-compile-cache-lib@^3.0.1:
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"
integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==

vary@~1.1.2:
vary@^1, vary@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==
Expand Down
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@openfort/openfort-node": "^0.6.66",
"@telegram-apps/sdk-react": "^2.0.5",
"@telegram-apps/telegram-ui": "^2.1.8",
"axios": "^1.7.7",
"buffer": "^6.0.3",
"eruda": "^3.4.0",
"express": "^4.21.1",
Expand Down
24 changes: 11 additions & 13 deletions frontend/src/services/openfortService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TypedDataField
} from '@openfort/openfort-js';
import openfort from '../utils/openfortConfig';
import axios from 'axios';

const chainId = Number(import.meta.env.VITE_CHAIN_ID);

Expand All @@ -32,19 +33,17 @@ class OpenfortService {
}
async mintNFT(identityToken: string): Promise<string | null> {
try {
const collectResponse = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/protected-collect`, {
method: "POST",
const collectResponse = await axios.post(`${import.meta.env.VITE_BACKEND_URL}/api/protected-collect`, {}, {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${identityToken}`,
},
});

if (!collectResponse.ok) {
if (collectResponse.status >= 400) {
alert("Failed to mint NFT status: " + collectResponse.status);
return null
}
const collectResponseJSON = await collectResponse.json();
const collectResponseJSON = await collectResponse.data.json();

if (collectResponseJSON.data?.nextAction) {
const response = await openfort.sendSignatureTransactionIntentRequest(
Expand Down Expand Up @@ -95,18 +94,17 @@ class OpenfortService {
async getEncryptionSession(): Promise<string> {
console.log('Creating encryption session');
console.log(import.meta.env.VITE_BACKEND_URL)
const resp = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/protected-create-encryption-session`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
const resp = await axios.post(`${import.meta.env.VITE_BACKEND_URL}/api/protected-create-encryption-session`,{}, {
headers: {
"Content-Type": "application/json",
},
});

if (!resp.ok) {
if (resp.status >= 400) {
throw new Error("Failed to create encryption session");
}

const respJSON = await resp.json();
const respJSON = await resp.data.json();
return respJSON.session;
}

Expand Down
11 changes: 10 additions & 1 deletion frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,15 @@ [email protected]:
form-data "^4.0.0"
proxy-from-env "^1.1.0"

axios@^1.7.7:
version "1.7.7"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.7.tgz#2f554296f9892a72ac8d8e4c5b79c14a91d0a47f"
integrity sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

balanced-match@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
Expand Down Expand Up @@ -2384,7 +2393,7 @@ flatted@^3.2.9:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.3.1.tgz#21db470729a6734d4997002f439cb308987f567a"
integrity sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==

follow-redirects@^1.15.4:
follow-redirects@^1.15.4, follow-redirects@^1.15.6:
version "1.15.9"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1"
integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==
Expand Down

0 comments on commit c65e491

Please sign in to comment.