From a0eb69a506413c09603b7a1d3e142f7c7b085ef4 Mon Sep 17 00:00:00 2001 From: Magne Cedric Date: Mon, 23 Sep 2024 17:18:47 +0200 Subject: [PATCH] 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();