Skip to content

Commit 2c27441

Browse files
committed
fix: env vars
1 parent bfac925 commit 2c27441

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

web/netlify/functions/authUser.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import { ethers } from "ethers";
55
import * as jwt from "jose";
66
import { SiweMessage } from "siwe";
77

8-
import { ETH_SIGNATURE_REGEX, DEFAULT_CHAIN } from "consts/processEnvConsts";
8+
import { ETH_SIGNATURE_REGEX, DEFAULT_CHAIN, isProductionDeployment } from "consts/processEnvConsts";
99

10-
import { getDefaultChainRpcUrl } from "src/context/Web3Provider";
1110
import { netlifyUri, netlifyDeployUri, netlifyDeployPrimeUri } from "src/generatedNetlifyInfo.json";
1211
import { Database } from "src/types/supabase-notification";
1312

@@ -75,8 +74,12 @@ const authUser = async (event) => {
7574
}
7675

7776
try {
78-
const rpcUrl = getDefaultChainRpcUrl("https");
79-
const provider = new ethers.providers.JsonRpcProvider(rpcUrl);
77+
const envVars = JSON.stringify(process.env, null, 2);
78+
console.info(`Environment variables: ${envVars}`);
79+
80+
const alchemyChain = isProductionDeployment() ? "arb-mainnet" : "arb-sepolia";
81+
const alchemyRpcURL = `https://${alchemyChain}.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`;
82+
const provider = new ethers.providers.JsonRpcProvider(alchemyRpcURL);
8083
await siweMessage.verify({ signature, nonce: nonceData.nonce, time: new Date().toISOString() }, { provider });
8184
} catch (err) {
8285
throw new Error("Invalid signer: " + JSON.stringify(err));

web/src/context/Web3Provider.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ const alchemyToViemChain = {
2222
[sepolia.id]: "eth-sepolia",
2323
};
2424

25+
type AlchemyProtocol = "https" | "wss";
26+
2527
// https://github.com/alchemyplatform/alchemy-sdk-js/blob/96b3f62/src/util/const.ts#L16-L18
26-
const alchemyURL = (protocol: "https" | "wss", chainId: number) =>
28+
const alchemyURL = (protocol: AlchemyProtocol, chainId: number) =>
2729
`${protocol}://${alchemyToViemChain[chainId]}.g.alchemy.com/v2/${alchemyApiKey}`;
2830

29-
export const getDefaultChainRpcUrl = (protocol: "https" | "wss") => {
30-
return alchemyURL(protocol, DEFAULT_CHAIN);
31+
export const getChainRpcUrl = (protocol: AlchemyProtocol, chainId: number) => {
32+
return alchemyURL(protocol, chainId);
33+
};
34+
35+
export const getDefaultChainRpcUrl = (protocol: AlchemyProtocol) => {
36+
return getChainRpcUrl(protocol, DEFAULT_CHAIN);
3137
};
3238

3339
export const getTransports = () => {

0 commit comments

Comments
 (0)