-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Reading SHOPIFY_API_KEY
via Vite define
instead of loader()
#798
Comments
Hi @kinngh thank you for the proposal! This makes sense to me, however I'll double check with the team to see if there are any gotchas here. |
Sure thing! If you want to see it in action, I've been working on a Remix boilerplate (it's broken in all sort of ways for now), but this specific part works. Vite Config: |
Great! One question is, do we need the |
I have seen that without the I also have a problem with aggressive caching in my setup so I cannot definitively state if we really do need the |
Hi @matteodepalo ! Putting my two cents here, We've done this in our app for a few months already, our approach is a bit different though: // app.tsx
import { PUBLIC_ENV } from '~/constants/app';
<AppProvider isEmbeddedApp apiKey={PUBLIC_ENV.VITE_SHOPIFY_API_KEY}> // constants file, or you can just use directly in the app.tsx
const { VITE_SHOPIFY_API_KEY, ...otherstuff } = import.meta.env;
export const PUBLIC_ENV = {
VITE_SHOPIFY_API_KEY,
} as const; // shopify.server.ts
const shopify = shopifyApp({
apiKey: process.env.VITE_SHOPIFY_API_KEY, // or from PUBLIC.ENV.VITE_SHOPIFY_API_KEY, its the same
..etc With our approach there was no need to mess with |
Thank you for the alternative approach @muchisx ! We've put this issue in our backlog. |
app/routes/app.tsx
pulls theSHOPIFY_API_KEY
from protected env via a loader, which is the Remix recommended way of reading envs client side in Remix.Since this requires making a fetch request on each page load OR building ways to persist across navigations, why not use Vite's
define
instead to read it, since the API key is completely find with being exposed to the client side?bun install dotenv -D
vite.config.ts
:app.tsx
:From my understanding, using Vite's
define
feature saves us at least onefetch()
to get the API key and allows shedding the (potential) persistence code since Vite now handles providing the right value(s) across the board?The text was updated successfully, but these errors were encountered: