Git Product home page Git Product logo

Comments (9)

nodece avatar nodece commented on June 8, 2024 1

TypeORMAdapter.newAdapter return is Promise, you forget use await.

from typeorm-adapter.

nodece avatar nodece commented on June 8, 2024

Can you provide a runnable example?

from typeorm-adapter.

Shaun-Li avatar Shaun-Li commented on June 8, 2024

Can you provide a runnable example?

Sorry, picture upload failed.

This is some code in config.default.ts:

config.middleware = ['user','authz'];
  config.authz = {
    enable: true,
    newEnforcer: async() => {
      const dbConnect = TypeORMAdapter.newAdapter({
        "type": "mysql",
        "host": "localhost",
        "port": 3306,
        "username": "root",
        "password": "123456",
        "database": "casbin"
      });
      const enforcer = await Enforcer.newEnforcer('authz_model.conf', dbConnect);
      return enforcer
    }
  }

router.ts

  router.get('/test', controller.home.test);

controller/home.ts

  public test() {
    const { ctx } = this;
    ctx.body = "this is a test";
  };

from typeorm-adapter.

nodece avatar nodece commented on June 8, 2024

Use node-casbin v2.0, you can try this

import casbin from 'casbin';
const enforcer = await casbin.newEnforcer('authz_model.conf', dbConnect);
return enforcer

from typeorm-adapter.

Shaun-Li avatar Shaun-Li commented on June 8, 2024

@nodece
use “ import casbin from 'casbin'; ” has error:

Module '"E:/workSpace/typeorm_test/node_modules/casbin/lib/index"' has no default export.

from typeorm-adapter.

nodece avatar nodece commented on June 8, 2024

ts use import * as casbin from 'casbin';

from typeorm-adapter.

Shaun-Li avatar Shaun-Li commented on June 8, 2024

@nodece
done as you said,still has this.adapter.loadPolicy is not a function......

from typeorm-adapter.

Shaun-Li avatar Shaun-Li commented on June 8, 2024

@nodece
done as you said,still has “this.adapter.loadPolicy is not a function”......

I use const dbConnect = await SequelizeAdapter.newAdapter('mysql://root:123456@localhost:3306/');
is ok;but const dbConnect = TypeORMAdapter.newAdapter(......) can't

from typeorm-adapter.

Shaun-Li avatar Shaun-Li commented on June 8, 2024

TypeORMAdapter.newAdapter return is Promise, you forget use await.

oh my god!!!
I am so sorry.
thank you very much!!

from typeorm-adapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.