Bird
0
0

Identify the error in this Remix code snippet that tries to expose a secret API key to the client:

medium📝 Debug Q14 of 15
Remix - Deployment
Identify the error in this Remix code snippet that tries to expose a secret API key to the client:
export function loader() {
  return { apiKey: process.env.SECRET_API_KEY };
}

export default function Component() {
  const { apiKey } = useLoaderData();
  return <div>API Key: {apiKey}</div>;
}
AMissing async keyword in loader function
Bprocess.env.SECRET_API_KEY is undefined in loader
CuseLoaderData cannot access loader return values
DExposing SECRET_API_KEY to client is a security risk
Step-by-Step Solution
Solution:
  1. Step 1: Understand environment variable exposure

    Secrets like API keys should never be sent to the client because it exposes sensitive data.
  2. Step 2: Analyze the code behavior

    The loader returns the secret key, which the component renders, exposing it in the browser.
  3. Final Answer:

    Exposing SECRET_API_KEY to client is a security risk -> Option D
  4. Quick Check:

    Never send secrets to client [OK]
Quick Trick: Never send secret env vars to client components [OK]
Common Mistakes:
MISTAKES
  • Thinking loader cannot access env vars
  • Believing useLoaderData can't access loader data
  • Assuming async is required for all loaders

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Remix Quizzes