forked from cerc-io/snowballtools-base
Refactor: Env to utils/constants
(#210)
This PR centralizes all the environment variable references into a single constants file. The change includes replacing various `import.meta.env` references with imports from the new `utils/constants` module. This improves maintainability by providing a single place to manage environment variables.
This commit is contained in:
parent
d975390a1b
commit
934aa1a26b
@ -1,3 +1,4 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
|
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
|
||||||
|
|
||||||
import Projects from './pages/org-slug';
|
import Projects from './pages/org-slug';
|
||||||
@ -10,8 +11,8 @@ import ProjectSearchLayout from './layouts/ProjectSearch';
|
|||||||
import Index from './pages';
|
import Index from './pages';
|
||||||
import AuthPage from './pages/AuthPage';
|
import AuthPage from './pages/AuthPage';
|
||||||
import { DashboardLayout } from './pages/org-slug/layout';
|
import { DashboardLayout } from './pages/org-slug/layout';
|
||||||
import { useEffect } from 'react';
|
|
||||||
import Web3Provider from 'context/Web3Provider';
|
import Web3Provider from 'context/Web3Provider';
|
||||||
|
import { baseUrl } from 'utils/constants';
|
||||||
|
|
||||||
const router = createBrowserRouter([
|
const router = createBrowserRouter([
|
||||||
{
|
{
|
||||||
@ -59,7 +60,7 @@ function App() {
|
|||||||
// Hacky way of checking session
|
// Hacky way of checking session
|
||||||
// TODO: Handle redirect backs
|
// TODO: Handle redirect backs
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(`${import.meta.env.VITE_SERVER_URL}/auth/session`, {
|
fetch(`${baseUrl}/auth/session`, {
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
|
@ -1,16 +1,21 @@
|
|||||||
|
import {
|
||||||
|
VITE_GITHUB_IMAGE_UPLOAD_PWA_TEMPLATE_REPO,
|
||||||
|
VITE_GITHUB_PWA_TEMPLATE_REPO,
|
||||||
|
} from 'utils/constants';
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
{
|
{
|
||||||
id: '1',
|
id: '1',
|
||||||
name: 'Progressive Web App (PWA)',
|
name: 'Progressive Web App (PWA)',
|
||||||
icon: 'pwa',
|
icon: 'pwa',
|
||||||
repoFullName: `${import.meta.env.VITE_GITHUB_PWA_TEMPLATE_REPO}`,
|
repoFullName: `${VITE_GITHUB_PWA_TEMPLATE_REPO}`,
|
||||||
isComingSoon: false,
|
isComingSoon: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '2',
|
id: '2',
|
||||||
name: 'Image Upload PWA',
|
name: 'Image Upload PWA',
|
||||||
icon: 'pwa',
|
icon: 'pwa',
|
||||||
repoFullName: `${import.meta.env.VITE_GITHUB_IMAGE_UPLOAD_PWA_TEMPLATE_REPO}`,
|
repoFullName: `${VITE_GITHUB_IMAGE_UPLOAD_PWA_TEMPLATE_REPO}`,
|
||||||
isComingSoon: false,
|
isComingSoon: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -14,11 +14,10 @@ import { useToast } from '../../shared/Toast';
|
|||||||
import { IconWithFrame } from '../../shared/IconWithFrame';
|
import { IconWithFrame } from '../../shared/IconWithFrame';
|
||||||
import { Heading } from '../../shared/Heading';
|
import { Heading } from '../../shared/Heading';
|
||||||
import { MockConnectGitCard } from './MockConnectGitCard';
|
import { MockConnectGitCard } from './MockConnectGitCard';
|
||||||
|
import { VITE_GITHUB_CLIENT_ID } from 'utils/constants';
|
||||||
|
|
||||||
const SCOPES = 'repo user';
|
const SCOPES = 'repo user';
|
||||||
const GITHUB_OAUTH_URL = `https://github.com/login/oauth/authorize?client_id=${
|
const GITHUB_OAUTH_URL = `https://github.com/login/oauth/authorize?client_id=${VITE_GITHUB_CLIENT_ID}&scope=${encodeURIComponent(SCOPES)}`;
|
||||||
import.meta.env.VITE_GITHUB_CLIENT_ID
|
|
||||||
}&scope=${encodeURIComponent(SCOPES)}`;
|
|
||||||
|
|
||||||
interface ConnectAccountInterface {
|
interface ConnectAccountInterface {
|
||||||
onAuth: (token: string) => void;
|
onAuth: (token: string) => void;
|
||||||
|
@ -20,6 +20,7 @@ import { cn } from 'utils/classnames';
|
|||||||
import { useMediaQuery } from 'usehooks-ts';
|
import { useMediaQuery } from 'usehooks-ts';
|
||||||
import { SIDEBAR_MENU } from './constants';
|
import { SIDEBAR_MENU } from './constants';
|
||||||
import { UserSelect } from 'components/shared/UserSelect';
|
import { UserSelect } from 'components/shared/UserSelect';
|
||||||
|
import { baseUrl } from 'utils/constants';
|
||||||
|
|
||||||
interface SidebarProps {
|
interface SidebarProps {
|
||||||
mobileOpen?: boolean;
|
mobileOpen?: boolean;
|
||||||
@ -83,7 +84,7 @@ export const Sidebar = ({ mobileOpen }: SidebarProps) => {
|
|||||||
}, [orgSlug]);
|
}, [orgSlug]);
|
||||||
|
|
||||||
const handleLogOut = useCallback(async () => {
|
const handleLogOut = useCallback(async () => {
|
||||||
await fetch(`${import.meta.env.VITE_SERVER_URL}/auth/logout`, {
|
await fetch(`${baseUrl}/auth/logout`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
});
|
});
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import { VITE_WALLET_CONNECT_ID } from 'utils/constants';
|
||||||
|
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
if (!import.meta.env.VITE_WALLET_CONNECT_ID) {
|
if (!VITE_WALLET_CONNECT_ID) {
|
||||||
throw new Error('Error: REACT_APP_WALLET_CONNECT_ID env config is not set');
|
throw new Error('Error: REACT_APP_WALLET_CONNECT_ID env config is not set');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import { GQLClientProvider } from './context/GQLClientContext';
|
|||||||
import { SERVER_GQL_PATH } from './constants';
|
import { SERVER_GQL_PATH } from './constants';
|
||||||
import { Toaster } from 'components/shared/Toast';
|
import { Toaster } from 'components/shared/Toast';
|
||||||
import { LogErrorBoundary } from 'utils/log-error';
|
import { LogErrorBoundary } from 'utils/log-error';
|
||||||
|
import { baseUrl } from 'utils/constants';
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
console.log(`v-${__VERSION__}`);
|
console.log(`v-${__VERSION__}`);
|
||||||
@ -22,8 +23,8 @@ const root = ReactDOM.createRoot(
|
|||||||
document.getElementById('root') as HTMLElement,
|
document.getElementById('root') as HTMLElement,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert(import.meta.env.VITE_SERVER_URL, 'VITE_SERVER_URL is not set in env');
|
assert(baseUrl, 'VITE_SERVER_URL is not set in env');
|
||||||
const gqlEndpoint = `${import.meta.env.VITE_SERVER_URL}/${SERVER_GQL_PATH}`;
|
const gqlEndpoint = `${baseUrl}/${SERVER_GQL_PATH}`;
|
||||||
|
|
||||||
const gqlClient = new GQLClient({ gqlEndpoint });
|
const gqlClient = new GQLClient({ gqlEndpoint });
|
||||||
|
|
||||||
|
11
packages/frontend/src/utils/constants.ts
Normal file
11
packages/frontend/src/utils/constants.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
export const baseUrl = import.meta.env.VITE_SERVER_URL;
|
||||||
|
export const PASSKEY_WALLET_RPID = import.meta.env.VITE_PASSKEY_WALLET_RPID!;
|
||||||
|
export const TURNKEY_BASE_URL = import.meta.env.VITE_TURNKEY_API_BASE_URL!;
|
||||||
|
export const VITE_GITHUB_PWA_TEMPLATE_REPO = import.meta.env
|
||||||
|
.VITE_GITHUB_PWA_TEMPLATE_REPO;
|
||||||
|
export const VITE_GITHUB_IMAGE_UPLOAD_PWA_TEMPLATE_REPO = import.meta.env
|
||||||
|
.VITE_GITHUB_IMAGE_UPLOAD_PWA_TEMPLATE_REPO;
|
||||||
|
export const VITE_GITHUB_CLIENT_ID = import.meta.env.VITE_GITHUB_CLIENT_ID;
|
||||||
|
export const VITE_WALLET_CONNECT_ID = import.meta.env.VITE_WALLET_CONNECT_ID;
|
||||||
|
export const VITE_BUGSNAG_API_KEY = import.meta.env.VITE_BUGSNAG_API_KEY;
|
||||||
|
export const VITE_LIT_RELAY_API_KEY = import.meta.env.VITE_LIT_RELAY_API_KEY;
|
@ -1,21 +1,21 @@
|
|||||||
|
import React from 'react';
|
||||||
import Bugsnag from '@bugsnag/js';
|
import Bugsnag from '@bugsnag/js';
|
||||||
import BugsnagPluginReact from '@bugsnag/plugin-react';
|
import BugsnagPluginReact from '@bugsnag/plugin-react';
|
||||||
import BugsnagPerformance from '@bugsnag/browser-performance';
|
import BugsnagPerformance from '@bugsnag/browser-performance';
|
||||||
import React from 'react';
|
|
||||||
|
|
||||||
const bugsnagApiKey = import.meta.env.VITE_BUGSNAG_API_KEY;
|
import { VITE_BUGSNAG_API_KEY } from './constants';
|
||||||
|
|
||||||
if (bugsnagApiKey) {
|
if (VITE_BUGSNAG_API_KEY) {
|
||||||
Bugsnag.start({
|
Bugsnag.start({
|
||||||
apiKey: bugsnagApiKey,
|
apiKey: VITE_BUGSNAG_API_KEY,
|
||||||
plugins: [new BugsnagPluginReact()],
|
plugins: [new BugsnagPluginReact()],
|
||||||
});
|
});
|
||||||
BugsnagPerformance.start({ apiKey: bugsnagApiKey });
|
BugsnagPerformance.start({ apiKey: VITE_BUGSNAG_API_KEY });
|
||||||
}
|
}
|
||||||
|
|
||||||
export const errorLoggingEnabled = !!bugsnagApiKey;
|
export const errorLoggingEnabled = !!VITE_BUGSNAG_API_KEY;
|
||||||
|
|
||||||
export const LogErrorBoundary = bugsnagApiKey
|
export const LogErrorBoundary = VITE_BUGSNAG_API_KEY
|
||||||
? Bugsnag.getPlugin('react')!.createErrorBoundary(React)
|
? Bugsnag.getPlugin('react')!.createErrorBoundary(React)
|
||||||
: ({ children }: any) => children;
|
: ({ children }: any) => children;
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ export function logError(error: Error) {
|
|||||||
}
|
}
|
||||||
console.error(...errors);
|
console.error(...errors);
|
||||||
|
|
||||||
if (import.meta.env.VITE_BUGSNAG_API_KEY) {
|
if (VITE_BUGSNAG_API_KEY) {
|
||||||
Bugsnag.notify(error);
|
Bugsnag.notify(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ import { SiweMessage } from 'siwe';
|
|||||||
import { PKPEthersWallet } from '@lit-protocol/pkp-ethers';
|
import { PKPEthersWallet } from '@lit-protocol/pkp-ethers';
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
|
|
||||||
|
import { baseUrl } from './constants';
|
||||||
|
|
||||||
const domain = window.location.host;
|
const domain = window.location.host;
|
||||||
const origin = window.location.origin;
|
const origin = window.location.origin;
|
||||||
|
|
||||||
@ -17,7 +19,7 @@ export async function signInWithEthereum(
|
|||||||
);
|
);
|
||||||
const signature = await wallet.signMessage(message);
|
const signature = await wallet.signMessage(message);
|
||||||
|
|
||||||
const res = await fetch(`${import.meta.env.VITE_SERVER_URL}/auth/validate`, {
|
const res = await fetch(`${baseUrl}/auth/validate`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
import { TurnkeyClient, getWebAuthnAttestation } from '@turnkey/http';
|
import { TurnkeyClient, getWebAuthnAttestation } from '@turnkey/http';
|
||||||
import { WebauthnStamper } from '@turnkey/webauthn-stamper';
|
import { WebauthnStamper } from '@turnkey/webauthn-stamper';
|
||||||
|
|
||||||
const baseUrl = import.meta.env.VITE_SERVER_URL;
|
import { baseUrl, PASSKEY_WALLET_RPID, TURNKEY_BASE_URL } from './constants';
|
||||||
|
|
||||||
const PASSKEY_WALLET_RPID = import.meta.env.VITE_PASSKEY_WALLET_RPID!;
|
|
||||||
const TURNKEY_BASE_URL = import.meta.env.VITE_TURNKEY_API_BASE_URL!;
|
|
||||||
|
|
||||||
// All algorithms can be found here: https://www.iana.org/assignments/cose/cose.xhtml#algorithms
|
// All algorithms can be found here: https://www.iana.org/assignments/cose/cose.xhtml#algorithms
|
||||||
// We only support ES256, which is listed here
|
// We only support ES256, which is listed here
|
||||||
|
@ -5,16 +5,17 @@ import {
|
|||||||
LitGoogleAuth,
|
LitGoogleAuth,
|
||||||
LitPasskeyAuth,
|
LitPasskeyAuth,
|
||||||
} from '@snowballtools/auth-lit';
|
} from '@snowballtools/auth-lit';
|
||||||
|
import { VITE_LIT_RELAY_API_KEY } from './constants';
|
||||||
|
|
||||||
export const snowball = Snowball.withAuth({
|
export const snowball = Snowball.withAuth({
|
||||||
google: LitGoogleAuth.configure({
|
google: LitGoogleAuth.configure({
|
||||||
litRelayApiKey: import.meta.env.VITE_LIT_RELAY_API_KEY!,
|
litRelayApiKey: VITE_LIT_RELAY_API_KEY!,
|
||||||
}),
|
}),
|
||||||
// apple: LitAppleAuth.configure({
|
// apple: LitAppleAuth.configure({
|
||||||
// litRelayApiKey: import.meta.env.VITE_LIT_RELAY_API_KEY!,
|
// litRelayApiKey: VITE_LIT_RELAY_API_KEY!,
|
||||||
// }),
|
// }),
|
||||||
passkey: LitPasskeyAuth.configure({
|
passkey: LitPasskeyAuth.configure({
|
||||||
litRelayApiKey: import.meta.env.VITE_LIT_RELAY_API_KEY!,
|
litRelayApiKey: VITE_LIT_RELAY_API_KEY!,
|
||||||
}),
|
}),
|
||||||
}).create({
|
}).create({
|
||||||
initialChain: SnowballChain.sepolia,
|
initialChain: SnowballChain.sepolia,
|
||||||
|
Loading…
Reference in New Issue
Block a user