From c6fde0a4902bf8081452a3ea4985585544651461 Mon Sep 17 00:00:00 2001 From: Magne Cedric Date: Mon, 23 Sep 2024 15:49:56 +0200 Subject: [PATCH 1/3] fix(cors): fix profile sdk env --- src/lib/siwsrp/auth.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/siwsrp/auth.ts b/src/lib/siwsrp/auth.ts index b9f88d2415..843d974d82 100644 --- a/src/lib/siwsrp/auth.ts +++ b/src/lib/siwsrp/auth.ts @@ -1,3 +1,4 @@ +import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; import { SDK } from "@metamask/profile-sync-controller"; import jwt from "jsonwebtoken"; @@ -10,6 +11,8 @@ type HydraEnv = { }; const { AuthType, Env, getEnvUrls, JwtBearerAuth, Platform } = SDK; +const { siteConfig } = useDocusaurusContext(); +const { VERCEL_ENV } = siteConfig?.customFields || {}; export const AUTH_WALLET_SESSION_NAME = "auth.wallet.session"; export const AUTH_WALLET_TOKEN = "auth.wallet.token"; export const AUTH_WALLET_PROJECTS = "auth.wallet.projects"; @@ -17,7 +20,7 @@ export const AUTH_WALLET_PROJECTS = "auth.wallet.projects"; export const getHydraEnv = (): HydraEnv => { const platform = Platform.INFURA; - if (process.env.VERCEL_ENV === "production") { + if (VERCEL_ENV === "production") { return { ...getEnvUrls(Env.PRD), env: Env.PRD, From 32f25fb0484b229f8591fa818fa5349f1b73b5fd Mon Sep 17 00:00:00 2001 From: Magne Cedric Date: Mon, 23 Sep 2024 16:49:32 +0200 Subject: [PATCH 2/3] fix(cors): fix profile sdk env --- src/lib/siwsrp/auth.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib/siwsrp/auth.ts b/src/lib/siwsrp/auth.ts index 843d974d82..96409aa94d 100644 --- a/src/lib/siwsrp/auth.ts +++ b/src/lib/siwsrp/auth.ts @@ -1,7 +1,10 @@ -import useDocusaurusContext from "@docusaurus/useDocusaurusContext"; import { SDK } from "@metamask/profile-sync-controller"; import jwt from "jsonwebtoken"; +export const customFields = { + VERCEL_ENV: process.env.VERCEL_ENV, +}; + type HydraEnv = { authApiUrl: string; oidcApiUrl: string; @@ -11,8 +14,8 @@ type HydraEnv = { }; const { AuthType, Env, getEnvUrls, JwtBearerAuth, Platform } = SDK; -const { siteConfig } = useDocusaurusContext(); -const { VERCEL_ENV } = siteConfig?.customFields || {}; +const { VERCEL_ENV } = customFields; +console.log(VERCEL_ENV) export const AUTH_WALLET_SESSION_NAME = "auth.wallet.session"; export const AUTH_WALLET_TOKEN = "auth.wallet.token"; export const AUTH_WALLET_PROJECTS = "auth.wallet.projects"; @@ -53,7 +56,7 @@ export const auth = new JwtBearerAuth( }, { storage, - }, + } ); export const authenticateAndAuthorize = async () => { From a0eb69a506413c09603b7a1d3e142f7c7b085ef4 Mon Sep 17 00:00:00 2001 From: Magne Cedric Date: Mon, 23 Sep 2024 17:18:47 +0200 Subject: [PATCH 3/3] fix(cors): fix profile sdk env --- src/components/AuthLogin/AuthModal.tsx | 2 +- src/lib/siwsrp/auth.ts | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/components/AuthLogin/AuthModal.tsx b/src/components/AuthLogin/AuthModal.tsx index b4f0ce9218..d770dbf961 100644 --- a/src/components/AuthLogin/AuthModal.tsx +++ b/src/components/AuthLogin/AuthModal.tsx @@ -158,7 +158,7 @@ const AuthModal = ({ // Call Profile SDK API to retrieve Hydra Access Token & Wallet userProfile // Hydra Access Token will be used to fetch Infura API - const { accessToken, userProfile } = await authenticateAndAuthorize(); + const { accessToken, userProfile } = await authenticateAndAuthorize(VERCEL_ENV as string); const loginResponse = await ( await fetch( diff --git a/src/lib/siwsrp/auth.ts b/src/lib/siwsrp/auth.ts index 96409aa94d..89be18de94 100644 --- a/src/lib/siwsrp/auth.ts +++ b/src/lib/siwsrp/auth.ts @@ -1,10 +1,6 @@ import { SDK } from "@metamask/profile-sync-controller"; import jwt from "jsonwebtoken"; -export const customFields = { - VERCEL_ENV: process.env.VERCEL_ENV, -}; - type HydraEnv = { authApiUrl: string; oidcApiUrl: string; @@ -14,8 +10,7 @@ type HydraEnv = { }; const { AuthType, Env, getEnvUrls, JwtBearerAuth, Platform } = SDK; -const { VERCEL_ENV } = customFields; -console.log(VERCEL_ENV) +let VERCEL_ENV = 'development' export const AUTH_WALLET_SESSION_NAME = "auth.wallet.session"; export const AUTH_WALLET_TOKEN = "auth.wallet.token"; export const AUTH_WALLET_PROJECTS = "auth.wallet.projects"; @@ -59,8 +54,9 @@ export const auth = new JwtBearerAuth( } ); -export const authenticateAndAuthorize = async () => { +export const authenticateAndAuthorize = async (env: string) => { let accessToken: string, userProfile: SDK.UserProfile; + VERCEL_ENV = env; try { await auth.connectSnap(); accessToken = await auth.getAccessToken();