Skip to content
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

feat(shared): Support passing env source into runtime environment helpers [SDK-773] #1881

Closed
wants to merge 1 commit into from

Conversation

dimkl
Copy link
Contributor

@dimkl dimkl commented Oct 14, 2023

Description

Changes:

  • Support per-request env of Cloudflare workers
  • Add JSDoc with examples

Currently we cannot support per-request environment variables for helpers using the runtimeEnvironment helpers since we should pass the env parameter from fetch() handler down to all functions using it. An alternative way to support this is to manually copy these values into process.env (see Cloudflare ref).

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Packages affected

  • @clerk/clerk-js
  • @clerk/clerk-react
  • @clerk/nextjs
  • @clerk/remix
  • @clerk/types
  • @clerk/themes
  • @clerk/localizations
  • @clerk/clerk-expo
  • @clerk/backend
  • @clerk/clerk-sdk-node
  • @clerk/shared
  • @clerk/fastify
  • @clerk/chrome-extension
  • gatsby-plugin-clerk
  • build/tooling/chore

@dimkl dimkl self-assigned this Oct 14, 2023
@dimkl dimkl requested a review from a team as a code owner October 14, 2023 10:09
@changeset-bot
Copy link

changeset-bot bot commented Oct 14, 2023

🦋 Changeset detected

Latest commit: 3f73e9f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@clerk/shared Patch
@clerk/backend Patch
@clerk/clerk-js Patch
@clerk/clerk-expo Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/clerk-react Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch
gatsby-plugin-clerk Patch
@clerk/chrome-extension Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dimkl dimkl requested a review from anagstef October 16, 2023 16:22
…pers

We can support cases like per-request env in Cloudflare workers
@dimkl dimkl force-pushed the isomorphic-shared-helpers branch from a2149aa to 3f73e9f Compare October 16, 2023 16:25
@dimkl dimkl changed the title feat(shared): Support passing env source into runtime environment helpers feat(shared): Support passing env source into runtime environment helpers [SDK-773] Oct 16, 2023
// TODO: add support for import.meta.env.DEV that is being used by vite
return false;
const getRuntimeFromProcess = (env?: typeof process.env) => {
return env?.NODE_ENV;
Copy link
Member

Choose a reason for hiding this comment

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

@dimkl this one applies only on node environments, right?
Or, if you pass an env object, it should include a NODE_ENV property for this to work, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it applies for all runtimes (Node, Cloudflare Workers, ...).
If you pass an env object with the NODE_ENV property, it should work.
I probably need to test if the process.env type works for Vite and Cloudflare workers.

Copy link
Member

Choose a reason for hiding this comment

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

@dimkl That's what I meant. You need to have NODE_ENV in your passed object for this to work. NODE_ENV usually refers to node environments.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that this name is a bit misleading. At the moment the function assumes that NODE_ENV exists and that it's Node.js

You can do a check for the runtime like this: https://github.com/unjs/std-env/blob/main/src/runtimes.ts

Probably the whole "runtime" name (also for the file name) is a bit misleading as we only check the NODE_ENV environment 🤔

@dimkl dimkl closed this Oct 18, 2023
@dimkl dimkl deleted the isomorphic-shared-helpers branch October 18, 2023 12:46
@clerk-cookie
Copy link
Collaborator

This PR has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@clerk clerk locked as resolved and limited conversation to collaborators Oct 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants