middleware icon indicating copy to clipboard operation
middleware copied to clipboard

how to access env outside fetch, when working with oauth-handlers

Open KunalSin9h opened this issue 1 year ago • 3 comments

  githubAuth({
    client_id: Bun.env.GITHUB_ID,
    client_secret: Bun.env.GITHUB_SECRET,

I see, @yusukebe you have used Bun.env, but without using Bun how can i get the env from .env files.

KunalSin9h avatar Feb 16 '24 10:02 KunalSin9h

Hi @KunalSin9h

You may use the env() function in hono/adapter.

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

yusukebe avatar Feb 20 '24 11:02 yusukebe

If you're using node.js.

import process from 'node:process'
...
githubAuth({
    client_id: process.env.GITHUB_ID,
    client_secret: process.env.GITHUB_SECRET,

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

Or you can write the following:

app.use('*', async (c, next) => {
  await githubAuth({
    client_id: env(c),
    client_secret: env(c),
    //..
  })(c, next)
})

yusukebe avatar Aug 02 '24 01:08 yusukebe