Verified Commit 5e840488 authored by Aral Balkan's avatar Aral Balkan
Browse files

Await sodium library initialisation before using it. Fixes #40

parent c83ebb2e
......@@ -23,9 +23,10 @@ function startFeathersServer () {
// On first run of the server only, create a server secret. This
// If it doesn’t already exist, create a server secret. This
// server secret is used to sign the JSON Web Tokens that we use
// for stateless authentication.
// for stateless authentication. (This should only happen on first run of
// an instance unless the server secret is manually deleted on the server.)
async function createAndPersitServerSecretIfItDoesntAlreadyExist () {
if (!app.get('serverSecretFileExists')) {
......@@ -34,17 +35,14 @@ async function createAndPersitServerSecretIfItDoesntAlreadyExist () {
//'Server secret does not exist, creating this one time.')
try {
// Sodium’s initialisation is asynchronous. Wait for it complete before using it.
await sodium.ready
// Create a server secret as the owner of the site is registering. This is
// the secret that we will use to sign JSON Web Tokens (JWTs).
const serverSecret = sodium.randombytes_buf(sodium.crypto_pwhash_SALTBYTES)
const serverSecretInHex = sodium.to_hex(serverSecret)
const serverSecretObject = { serverSecret: serverSecretInHex }
} catch (error) {
const message = `Error trying to use sodium. ${error}`
throw new Error(message)
try {
// Write the keys file to a data file in a directory for this spike that
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment