[SOLVED] An error occurred when creating an index for collection "users: Authentication failed

Trying to host my meteor application on Galaxy, during the build I encountered this error which I suspect originates from my Accounts.js file that is parked under the server folder. What’s confusing is that when I run this on my local I face no issues… first time using Meteor and pushing onto Galaxy as a hosting service. Appreciate any help :slight_smile:

Accounts.js

import { Meteor } from "meteor/meteor";
import { Accounts } from "meteor/accounts-base";
import { Roles } from "meteor/alanning:roles";

/* eslint-disable no-console */

const createUser = (username, email, password, role) => {
  console.log(`  Creating user ${email}.`);
  const userID = Accounts.createUser({
    username: username,
    email: email,
    password: password,
  });
  if (role === "admin") {
    Roles.createRole(role, { unlessExists: true });
    Roles.addUsersToRoles(userID, "admin");
  }
  if (role === "org") {
    Roles.createRole(role, { unlessExists: true });
    Roles.addUsersToRoles(userID, "org");
  }
  if (role === "seeker") {
    Roles.createRole(role, { unlessExists: true });
    Roles.addUsersToRoles(userID, "seeker");
  }
};

// When running app for first time, pass a settings file to set up a default user account.
if (Meteor.users.find().count() === 0) {
  if (Meteor.settings.defaultAccounts) {
    console.log("Creating the default user(s)");
    Meteor.settings.defaultAccounts.forEach(
      ({ username, email, password, role }) =>
        createUser(username, email, password, role)
    );
  } else {
    console.log(
      "Cannot initialize the database!  Please invoke meteor with a settings file."
    );
  }
}

the settings folder I feed to the deployment argument --settings ./settings.json contains the following

{
"defaultAccounts": [
    {
      "username": "jane@foo.com",
      "email": "jane@foo.com",
      "password": "changeme",
      "role": "admin"
    },
    {
      "username": "john@foo.com",
      "email": "john@foo.com",
      "password": "changeme",
      "role": "seeker"
    },
    {
      "username": "SPCA",
      "email": "org@foo.com",
      "password": "changeme",
      "role": "org"
    }
  ],
}

the error that recurs in the meteor cloud log is as follows:

n0v0p
2023-06-19 22:37:14+08:00/app/bundle/programs/server/node_modules/fibers/future.js:313n0v0p
2023-06-19 22:37:14+08:00 throw(ex);n0v0p
2023-06-19 22:37:14+08:00 ^n0v0p
2023-06-19 22:37:16+08:00errorClass [Error]: [An error occurred when creating an index for collection "users: Authentication failed.]n0v0p
2023-06-19 22:37:16+08:00 at Collection.createIndex (packages/mongo/collection.js:801:15)n0v0p
2023-06-19 22:37:16+08:00 at setupUsersCollection (packages/accounts-base/accounts_server.js:1776:9)n0v0p
2023-06-19 22:37:16+08:00 at new AccountsServer (packages/accounts-base/accounts_server.js:75:5)n0v0p
2023-06-19 22:37:16+08:00 at packages/accounts-base/server_main.js:7:12n0v0p
2023-06-19 22:37:16+08:00 at module (packages/accounts-base/server_main.js:19:31)n0v0p
2023-06-19 22:37:16+08:00 at fileEvaluate (packages/modules-runtime.js:336:7)n0v0p
2023-06-19 22:37:16+08:00 at Module.require (packages/modules-runtime.js:238:14)n0v0p
2023-06-19 22:37:16+08:00 at require (packages/modules-runtime.js:258:21)n0v0p
2023-06-19 22:37:16+08:00 at /app/bundle/programs/server/packages/accounts-base.js:2192:15n0v0p
2023-06-19 22:37:16+08:00 at /app/bundle/programs/server/packages/accounts-base.js:2199:3n0v0p
2023-06-19 22:37:16+08:00 at /app/bundle/programs/server/boot.js:369:38n0v0p
2023-06-19 22:37:16+08:00 at Array.forEach (<anonymous>)n0v0p
2023-06-19 22:37:16+08:00 at /app/bundle/programs/server/boot.js:210:21n0v0p
2023-06-19 22:37:16+08:00 at /app/bundle/programs/server/boot.js:423:7n0v0p
2023-06-19 22:37:16+08:00 at Function.run (/app/bundle/programs/server/profile.js:256:14)n0v0p
2023-06-19 22:37:16+08:00 at /app/bundle/programs/server/boot.js:422:13 {n0v0p
2023-06-19 22:37:16+08:00 isClientSafe: true,n0v0p
2023-06-19 22:37:16+08:00 error: 'An error occurred when creating an index for collection "users: Authentication failed.',n0v0p
2023-06-19 22:37:16+08:00 reason: undefined,n0v0p
2023-06-19 22:37:16+08:00 details: undefined,n0v0p
2023-06-19 22:37:16+08:00 errorType: 'Meteor.Error'n0v0p
2023-06-19 22:37:16+08:00}

Hi there. So how is your database set up? When running things locally, meteor creates a local mongoDB database for you. While on Galaxy, you need to provide one yourself. Have you set that up and connected it correctly? Sounds like a permission / connection issue there. The accounts package might just be the first package in your project to try doing database operations.

1 Like

Yes, you’re exactly right! Configured my own mongoDB atlas cluster with its respective db and used that for the mongoURL env var in the settings folder. To note I decided to reply via the meteor CLI route instead and not sure if that made a change too.

Thanks for your time :slight_smile: will be closing this