From d0a80061273151c37d7f83611dd663ea32efbcf0 Mon Sep 17 00:00:00 2001 From: anoopkarnik Date: Wed, 4 Sep 2024 04:34:57 +0530 Subject: [PATCH] Environment variables using server actions now --- apps/dashboard-app/app/actions/env/env.ts | 14 ++++++++++++++ .../components/ConnectionCard.tsx | 19 ++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 apps/dashboard-app/app/actions/env/env.ts diff --git a/apps/dashboard-app/app/actions/env/env.ts b/apps/dashboard-app/app/actions/env/env.ts new file mode 100644 index 0000000..de6b373 --- /dev/null +++ b/apps/dashboard-app/app/actions/env/env.ts @@ -0,0 +1,14 @@ +"use server" + +export async function getEnvironmentVariables(){ + var res:any = {} + res["NEXT_PUBLIC_RESEND_API_KEY"] = process.env.NEXT_PUBLIC_RESEND_API_KEY + res["NEXT_PUBLIC_URL"] = process.env.NEXT_PUBLIC_URL + res["NEXT_PUBLIC_YOUTUBE_OAUTH_URL"] = process.env.NEXT_PUBLIC_YOUTUBE_OAUTH_URL + res["NEXT_PUBLIC_NOTION_CLIENT_ID"] = process.env.NEXT_PUBLIC_NOTION_CLIENT_ID + res["NEXT_PUBLIC_NOTION_CLIENT_SECRET"] = process.env.NEXT_PUBLIC_NOTION_CLIENT_SECRET + res["NEXT_PUBLIC_NOTION_REDIRECT_URI"] = process.env.NEXT_PUBLIC_NOTION_REDIRECT_URI + res["NEXT_PUBLIC_NOTION_OAUTH_URL"] = process.env.NEXT_PUBLIC_NOTION_OAUTH_URL + return res + +} \ No newline at end of file diff --git a/apps/dashboard-app/components/ConnectionCard.tsx b/apps/dashboard-app/components/ConnectionCard.tsx index 928d443..9fe3d3f 100644 --- a/apps/dashboard-app/components/ConnectionCard.tsx +++ b/apps/dashboard-app/components/ConnectionCard.tsx @@ -10,6 +10,7 @@ import AddConnectionsModal from './AddConnectionModal' import { useSession } from 'next-auth/react' import { createOpenAIConnection } from '../app/actions/connections/openai-connections' import { useRouter } from 'next/navigation' +import { getEnvironmentVariables } from '../app/actions/env/env' const ConnectionCard = ({connection}:any) => { @@ -32,14 +33,18 @@ const ConnectionCard = ({connection}:any) => { } useEffect(() => { - setAppType(connection.title) - if (connection.title === 'Notion'){ - setOauthUrl(process.env.NEXT_PUBLIC_NOTION_OAUTH_URL as string) - } - else if (connection.title === 'Youtube'){ - setCallbackUrl(process.env.NEXT_PUBLIC_URL+'/api/callback/youtube') - setOauthUrl(process.env.NEXT_PUBLIC_YOUTUBE_OAUTH_URL as string) + const updateEnvironmentVariables = async () => { + setAppType(connection.title) + const res = await getEnvironmentVariables(); + if (connection.title === 'Notion'){ + setOauthUrl(res["NEXT_PUBLIC_NOTION_OAUTH_URL"] ) + } + else if (connection.title === 'Youtube'){ + setCallbackUrl(res["NEXT_PUBLIC_URL"]+'/api/callback/youtube') + setOauthUrl(res["NEXT_PUBLIC_YOUTUBE_OAUTH_URL"]) + } } + updateEnvironmentVariables() },[connection.title]) const handleConnect = () => {