How to use private remote modules hosted on GitHub on Deno Deploy?
According to Private Modules and Repositories, I can access a private GitHub repo using the
DENO_AUTH_TOKENS
environment variable. How do I achieve this on Deno Deploy? I've tried setting DENO_AUTH_TOKEN
on my project's settings page but it suggests that DENO_
is a reserved prefix.3 Replies
To use private GitHub repositories as dependencies in Deno Deploy, you'll need to authenticate access to these private modules using the
DENO_AUTH_TOKENS
environment variable. However, since Deno Deploy reserves environment variables starting with DENO_
, you cannot directly set DENO_AUTH_TOKENS
in the Deno Deploy dashboard.
Here's a workaround you can use:
1. Create an environment variable in the Deno Deploy dashboard with a different name, such as GH_AUTH_TOKENS
.
2. In your code, before you import any private modules, set the DENO_AUTH_TOKENS
environment variable using the value from GH_AUTH_TOKENS
. You can do this by accessing the environment variables using Deno.env.get("GH_AUTH_TOKENS")
and then setting DENO_AUTH_TOKENS
accordingly.
Here's a small code snippet to illustrate this (please note that this is general advice and not a direct code example from the documentation):
Make sure to replace the placeholders with your actual GitHub token, user, repository, branch, and module path.
Remember, this is a general approach and you should ensure that your token is kept secure and not exposed in your code. 🦕I think it fails during caching when deploying?
This is how I import my module in my code
Can confirm caching does not work if the environment variable is not set