Skip to content

Commit

Permalink
fix: web3auth network type validation
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency committed Dec 6, 2024
1 parent 67ed180 commit c33b25b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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) =>
Expand Down

0 comments on commit c33b25b

Please sign in to comment.