middleware icon indicating copy to clipboard operation
middleware copied to clipboard

docs(oauth-providers): use process.env instead of Bun.env as default

Open euxn23 opened this issue 1 year ago • 6 comments

Now Bun is not standard, so I think README should use process.env instead of Bun.env, so I replaced Bun.env to process.env in this PR. But there is a difference between Bun.env and process.env, I also added note about Bun.

euxn23 avatar Jul 03 '24 00:07 euxn23

⚠️ No Changeset found

Latest commit: fba3d9e38d618aa39259294fb81df09aba940f43

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

changeset-bot[bot] avatar Jul 03 '24 00:07 changeset-bot[bot]

Hi @euxn23

Regarding env variables, we can use the adapter helper:

https://hono.dev/docs/helpers/adapter#env

import { env } from 'hono/adapter'

app.get('/env', (c) => {
  // NAME is process.env.NAME on Node.js or Bun
  // NAME is the value written in `wrangler.toml` on Cloudflare
  const { NAME } = env<{ NAME: string }>(c)
  return c.text(NAME)
})

I think using this would be better than using other runtime-specific variables.

yusukebe avatar Jul 03 '24 09:07 yusukebe

Hi @euxn23

Regarding env variables, we can use the adapter helper:

https://hono.dev/docs/helpers/adapter#env

import { env } from 'hono/adapter'

app.get('/env', (c) => {
  // NAME is process.env.NAME on Node.js or Bun
  // NAME is the value written in `wrangler.toml` on Cloudflare
  const { NAME } = env<{ NAME: string }>(c)
  return c.text(NAME)
})

I think using this would be better than using other runtime-specific variables.

But env() requires a c: Context param, which we cannot get out of a handler.

nick-cjyx9 avatar Aug 01 '24 04:08 nick-cjyx9

the same question in #398

nick-cjyx9 avatar Aug 01 '24 05:08 nick-cjyx9

Hi @nick-cjyx9

But env() requires a c: Context param, which we cannot get out of a handler.

You are right. If you want to use environment variables out of a handler, you have to use Bun.env, process.env, or another runtime-dependent variable. In this case, it will be used in the middleware handler, so we have to use env().

yusukebe avatar Aug 02 '24 01:08 yusukebe

Hi @euxn23

Regarding env variables, we can use the adapter helper:

https://hono.dev/docs/helpers/adapter#env

import { env } from 'hono/adapter'

app.get('/env', (c) => {
  // NAME is process.env.NAME on Node.js or Bun
  // NAME is the value written in `wrangler.toml` on Cloudflare
  const { NAME } = env<{ NAME: string }>(c)
  return c.text(NAME)
})

I think using this would be better than using other runtime-specific variables.

Is there any way to have env() automatically parse the .env file and generate types?

doroved avatar Apr 30 '25 11:04 doroved