Skip to content

Commit

Permalink
fix(builder): 🐛 Add public env var in runtime config
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jun 7, 2022
1 parent 853b749 commit a42e1ca
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import { BaseEmoji, emojiIndex } from 'emoji-mart'
import { emojis } from './emojis'
import { Input } from '../Textbox/Input'
import { isEmpty } from 'utils'
import getConfig from 'next/config'

const {
publicRuntimeConfig: { NEXT_PUBLIC_GIPHY_API_KEY },
} = getConfig()

type Props = {
url?: string
Expand Down Expand Up @@ -183,12 +188,10 @@ const EmojiContent = ({
}

const GiphyContent = ({ onNewUrl }: ContentProps) => {
if (isEmpty(process.env.NEXT_PUBLIC_GIPHY_API_KEY))
if (isEmpty(NEXT_PUBLIC_GIPHY_API_KEY))
return <Text>NEXT_PUBLIC_GIPHY_API_KEY is missing in environment</Text>
return (
<SearchContextManager
apiKey={process.env.NEXT_PUBLIC_GIPHY_API_KEY as string}
>
<SearchContextManager apiKey={NEXT_PUBLIC_GIPHY_API_KEY}>
<GiphySearch onSubmit={onNewUrl} />
</SearchContextManager>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react'
import { Text, HStack } from '@chakra-ui/react'
import { SearchableDropdown } from '../../../shared/SearchableDropdown'
import { isEmpty } from 'utils'
import getConfig from 'next/config'

type FontSelectorProps = {
activeFont?: string
Expand All @@ -20,9 +21,12 @@ export const FontSelector = ({
}, [])

const fetchPopularFonts = async () => {
if (isEmpty(process.env.NEXT_PUBLIC_GOOGLE_API_KEY)) return []
const {
publicRuntimeConfig: { NEXT_PUBLIC_GOOGLE_API_KEY },
} = getConfig()
if (isEmpty(NEXT_PUBLIC_GOOGLE_API_KEY)) return []
const response = await fetch(
`https://www.googleapis.com/webfonts/v1/webfonts?key=${process.env.NEXT_PUBLIC_GOOGLE_API_KEY}&sort=popularity`
`https://www.googleapis.com/webfonts/v1/webfonts?key=${NEXT_PUBLIC_GOOGLE_API_KEY}&sort=popularity`
)
return (await response.json()).items.map(
(item: { family: string }) => item.family
Expand Down
5 changes: 5 additions & 0 deletions apps/builder/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const moduleExports = {
outputStandalone: true,
},
optimizeFonts: false,
publicRuntimeConfig: {
NEXT_PUBLIC_GOOGLE_API_KEY: process.env.NEXT_PUBLIC_GOOGLE_API_KEY,
NEXT_PUBLIC_GIPHY_API_KEY: process.env.NEXT_PUBLIC_GIPHY_API_KEY,
NEXT_PUBLIC_STRIPE_PUBLIC_KEY: process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY,
},
}

const sentryWebpackPluginOptions = {
Expand Down
8 changes: 6 additions & 2 deletions apps/builder/services/stripe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Plan, User } from 'db'
import { loadStripe } from '@stripe/stripe-js/pure'
import { isDefined, isEmpty, sendRequest } from 'utils'
import getConfig from 'next/config'

type Props = {
user: User
Expand Down Expand Up @@ -39,7 +40,10 @@ const redirectToCheckout = async ({
plan,
workspaceId,
}: Omit<Props, 'customerId'>) => {
if (isEmpty(process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY))
const {
publicRuntimeConfig: { NEXT_PUBLIC_STRIPE_PUBLIC_KEY },
} = getConfig()
if (isEmpty(NEXT_PUBLIC_STRIPE_PUBLIC_KEY))
throw new Error('NEXT_PUBLIC_STRIPE_PUBLIC_KEY is missing in env')
const { data, error } = await sendRequest<{ sessionId: string }>({
method: 'POST',
Expand All @@ -53,7 +57,7 @@ const redirectToCheckout = async ({
},
})
if (error || !data) return
const stripe = await loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY)
const stripe = await loadStripe(NEXT_PUBLIC_STRIPE_PUBLIC_KEY)
await stripe?.redirectToCheckout({
sessionId: data?.sessionId,
})
Expand Down

4 comments on commit a42e1ca

@vercel
Copy link

@vercel vercel bot commented on a42e1ca Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
app.typebot.io
builder-v2-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on a42e1ca Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on a42e1ca Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on a42e1ca Jun 7, 2022

Please sign in to comment.