Skip to content

Instantly share code, notes, and snippets.

@acomito
Last active February 13, 2021 14:36
Show Gist options
  • Save acomito/b6969d6121254eeffa54be431a3f2262 to your computer and use it in GitHub Desktop.
Save acomito/b6969d6121254eeffa54be431a3f2262 to your computer and use it in GitHub Desktop.
migrating a meteor accounts system to accountsjs
  1. Make sure accountsjs knows to look for an _id that is a string
db: new MongoDBInterface(db, {
  convertUserIdToMongoObjectId: false, // this is the required change
  convertSessionIdToMongoObjectId: false, // unsure if this is required
  idProvider, // unsure if this is required
  dateProvider, // unsure if this is required
}),

const METEOR_ID_LENGTH = 17;

const idProvider = () =>
  randomBytes(30)
    .toString('base64')
    .replace(/[\W_]+/g, '')
    .substr(0, METEOR_ID_LENGTH);

const dateProvider = (date) => date || new Date();
  1. on the frontend, hash the password before passing it to functions (like authenticate). Below is calling the graphql mutation. This will be needed, at the very least, for authenticate, changePassword and signup.
// import the hashing libraru
import { SHA256 } from 'crypto-js';

// ... 

// then in your login function, hash the password before passing to the mutation

const handleLogin = (email, password) => {

      const hashedPassword = SHA256(password);

      await this.props.authenticate({
        variables: {
          params: {
            password: hashedPassword.toString(),
            user: {
              email,
            },
          },
        },
      });

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment