juicycleff / casbin-mongodb-adapter

Pure MongoDB adapter for Casbin
MIT License
9 stars 18 forks source link

Mongodb client isConnected property is deprecated #21

Open JinYuSha0 opened 2 years ago

JinYuSha0 commented 2 years ago

see https://github.com/mongodb/node-mongodb-native/commit/5a37a9244aa8a3ca0ce137c42f6593d99aca98ee

and then will throw error: Casbin mongo adapter not connected

if (this.mongoClient.isConnected === undefined) {
  throw new Error('Casbin mongo adapter not connected');
}
JinYuSha0 commented 2 years ago

That's how I solved it for now

async function loadEnforcer() {
  const model = path.resolve(__dirname, "../config/rbac_model.conf");

  const adapter = await MongoAdapter.newAdapter({
    uri: process.env.DATABASE_URL,
    option: {
      useNewUrlParser: true,
    },
    database: process.env.DATABASE_NAME,
    collection: "casbin",
  });

  await adapter.mongoClient.connect();

  const e = new Enforcer();

  await e.initWithAdapter(model, adapter, true);

  adapter.mongoClient.isConnected = true;

  await e.loadPolicy();

  return e;
}
hsluoyz commented 2 years ago

@JinYuSha0 can you make a PR to fix it?

hsluoyz commented 2 years ago

@juicycleff

JinYuSha0 commented 2 years ago

@JinYuSha0 can you make a PR to fix it?

I can offer a PR as early as tomorrow

juicycleff commented 2 years ago

Updating this package soon

juicycleff commented 2 years ago

anyone wants to be added as a contributor please let me know