From c33b25bc3d0bca7749f86139fa6905a529c1a1fb Mon Sep 17 00:00:00 2001 From: "Felix C. Morency" <1102868+fmorency@users.noreply.github.com> Date: Fri, 6 Dec 2024 13:22:39 -0500 Subject: [PATCH] fix: web3auth network type validation --- pages/_app.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pages/_app.tsx b/pages/_app.tsx index 16139db7..53dc8f31 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -40,7 +40,7 @@ import MobileNav from '@/components/react/mobileNav'; import { useEndpointStore } from '@/store/endpointStore'; import EndpointSelector from '@/components/react/endpointSelector'; -import { OPENLOGIN_NETWORK_TYPE } from '@toruslabs/openlogin-utils'; +import { OPENLOGIN_NETWORK, OPENLOGIN_NETWORK_TYPE } from '@toruslabs/openlogin-utils'; type ManifestAppProps = AppProps & { Component: AppProps['Component']; @@ -112,6 +112,16 @@ function ManifestApp({ Component, pageProps }: ManifestAppProps) { } | undefined >(); + + const isValidNetwork = (network: string | undefined): network is OPENLOGIN_NETWORK_TYPE => { + return Object.values(OPENLOGIN_NETWORK).includes(network as OPENLOGIN_NETWORK_TYPE); + }; + + const network = process.env.NEXT_PUBLIC_WEB3AUTH_NETWORK; + if (!isValidNetwork(network)) { + console.error(`Invalid WEB3AUTH_NETWORK: ${network}. Using default: testnet`); + } + const web3AuthWallets = useMemo( () => makeWeb3AuthWallets({ @@ -150,8 +160,7 @@ function ManifestApp({ Component, pageProps }: ManifestAppProps) { client: { clientId: process.env.NEXT_PUBLIC_WEB3AUTH_CLIENT_ID ?? '', - web3AuthNetwork: - (process.env.NEXT_PUBLIC_WEB3AUTH_NETWORK as OPENLOGIN_NETWORK_TYPE) ?? '', + web3AuthNetwork: isValidNetwork(network) ? network : 'testnet', }, promptSign: async (_, signData) =>