diff --git a/src/lib/session.ts b/src/lib/session.ts index ce071a1d..d94572ec 100644 --- a/src/lib/session.ts +++ b/src/lib/session.ts @@ -14,5 +14,6 @@ export const sessionOptions: IronSessionOptions = { declare module "iron-session" { interface IronSessionData { user?: User | null; + envVariables?: {[key: string]: string}; } } diff --git a/src/pages/index.tsx b/src/pages/index.tsx index ef87f200..72885d11 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -32,6 +32,13 @@ import {env} from "@/utils"; export const getServerSideProps = withIronSessionSsr(({req, res}) => { const user = req.session.user; + const envVariables: {[key: string]: string} = {}; + Object.keys(process.env) + .filter((x) => x.startsWith("NEXT_PUBLIC")) + .forEach((x: string) => { + envVariables[x] = process.env[x]!; + }); + if (!user || !user.isVerified) { res.setHeader("location", "/login"); res.statusCode = 302; @@ -39,23 +46,24 @@ export const getServerSideProps = withIronSessionSsr(({req, res}) => { return { props: { user: null, + envVariables, }, }; } return { - props: {user: req.session.user}, + props: {user: req.session.user, envVariables}, }; }, sessionOptions); -export default function Home() { +export default function Home({envVariables}: {envVariables: {[key: string]: string}}) { const [showDiagnostics, setShowDiagnostics] = useState(false); const [showDemographicInput, setShowDemographicInput] = useState(false); const {user, mutateUser} = useUser({redirectTo: "/login"}); useEffect(() => { - console.log({env: env("NEXT_PUBLIC_TEST")}); - }, []); + console.log({env: envVariables["NEXT_PUBLIC_TEST"]}); + }, [envVariables]); useEffect(() => { if (user) {