mirror of
https://github.com/NovaOSS/nova-web.git
synced 2024-11-25 21:13:58 +01:00
72 lines
2.9 KiB
HTML
72 lines
2.9 KiB
HTML
{% include 'common/begin.html' %}
|
|
<link rel="stylesheet" href="/static/css/home.css">
|
|
|
|
<main>
|
|
<h1>Prevent your API keys and Discord bot tokens from being stolen when using replit</h1>
|
|
<p>
|
|
Everyone can see your code created using <a href="https://replit.com">replit</a>.<br>
|
|
It's really important that you don't set your API keys and other secret credentials directly in your code.
|
|
This isn't just for NovaAI, but for all your projects.
|
|
</p>
|
|
<h2>How to add new secrets</h2>
|
|
<p>
|
|
It's really simple:
|
|
<ol>
|
|
<li>
|
|
Click the <mark><i class="bi bi-lock"></i></mark> lock icon in the left sidebar
|
|
</li>
|
|
<li>
|
|
Set <code>key</code> to something like <code>NOVA_API_KEY</code> or <code>DISCORD_BOT_TOKEN</code> (don't use spaces etc.)
|
|
and the field <code>value</code> to your API key/token that you want to hide.
|
|
</li>
|
|
<li>
|
|
Click <mark>Add new secret</mark>
|
|
</li>
|
|
<li>
|
|
Now, you'll need to change the code a bit. Don't worry, it's just one or two lines.
|
|
</li>
|
|
</ol>
|
|
</p>
|
|
|
|
<h2>How to use secrets in your code</h2>
|
|
<p>In the following example, we're assuming you have just created a new <code>NOVA_API_KEY</code> secret.</p>
|
|
|
|
<h3>Python</h3>
|
|
<p>To set the variable <code>nova_api_key</code> to the value of the secret, use the following code:</p>
|
|
<pre><code class="language-python">import os
|
|
|
|
nova_api_key = os.environ['NOVA_API_KEY']</code></pre>
|
|
</code></pre>
|
|
|
|
<p>For example, if you want to use the <code>openai</code> Python library, your code might look a bit like this:</p>
|
|
<pre><code class="language-python">import openai as novaai
|
|
import os
|
|
|
|
novaai.api_base = 'https://api.nova-oss.com/v1'
|
|
novaai.api_key = os.environ['NOVA_API_KEY']
|
|
|
|
# ...</code></pre>
|
|
|
|
|
|
<h3>Node.js</h3>
|
|
<p>To set the variable <code>novaApiKey</code> to the value of the secret, use the following code:</p>
|
|
<pre><code class="language-javascript">const novaApiKey = process.env.NOVA_API_KEY</code></pre>
|
|
|
|
<p>If you're using <code>discord.js</code>, your code might look a bit like this:</p>
|
|
<pre><code class="language-javascript">const Discord = require('discord.js')
|
|
const client = new Discord.Client()
|
|
// ...
|
|
client.login(process.env.DISCORD_BOT_TOKEN)</code></pre>
|
|
|
|
<h2>Need help?</h2>
|
|
<p>
|
|
Learn more in the <a href="https://docs.replit.com/programming-ide/workspace-features/secrets">replit documentation</a>
|
|
Here's a nice, well explained video tutorial by the team behind replit on how to use secrets:
|
|
<a href="https://youtu.be/Xrg2XP1JJec">https://youtu.be/Xrg2XP1JJec</a>
|
|
And here's a shorter, but unofficial video tutorial by
|
|
<a href="https://youtu.be/BKlv__1OoGc?t=24">https://youtu.be/BKlv__1OoGc?t=24</a>.
|
|
</p>
|
|
</main>
|
|
|
|
{% include 'common/end.html' %}
|