如何将 account-js 包集成到已经存在的 mongo 数据库中?

How to integrate account-js package to already existed mongo db?

我有一个 meteor 应用程序,想迁移非 meteor 应用程序。我发现 account-js 与流星帐户系统兼容。当我创建新用户时,一切正常,但如果我想使用已经存在的用户帐户登录,js 方法不起作用,我每次都会收到未经授权的消息。如何使用account-js登录已有用户?

   
const accountsPassword = new AccountsPassword({
  verifyPassword: (plainPassword, storedPassword) => {
    const hashedPassword = crypto.Hash('sha256').update(plainPassword).digest('hex')

    console.log('*****Verify Password*****')
    return bcrypt.compareSync(plainPassword, storedPassword)
  }
})

const accountsServer = new AccountsServer(
  {
    db: accountsMongo
  },
  {
    password: accountsPassword
  }
)

const accountsGraphQL = AccountsModule.forRoot({ accountsServer })


const schema = makeExecutableSchema({
  typeDefs: mergeTypeDefs([typeDefs, accountsGraphQL.typeDefs]),
  resolvers: mergeResolvers([resolvers, accountsGraphQL.resolvers]),
  schemaDirectives: {
    ...accountsGraphQL.schemaDirectives
  }
})

const schemaMiddleware = applyMiddleware(schema, permissions)

accounts-js 使用与 Meteor 身份验证系统完全不同的身份验证机制。 accounts-js 使用 JWT 令牌,而 Meteor 使用唯一哈希,因此它不交叉兼容。我写了一篇关于它的博客 post,你可以阅读 here