@phenyl/standards
TypeScript icon, indicating that this package has built-in type declarations

4.1.0 • Public • Published

phenyl/standards

Standards has templates for user definition.

example

You can define authentication and authorization by extending StandardUserDefinition. See here for how to create a PhenylRestApi instance using the userDefinition.

import { StandardUserDefinition } from "@phenyl/standards";
import { EntityDefinition } from "@phenyl/interfaces";

class UserDefinition extends StandardUserDefinition {
  constructor(entityClient) {
    super({
      entityClient,
      accountPropName: "email",
      passwordPropName: "password",
      ttl: 1000 * 60 * 60,
    });
  }
}

class NonUserDefinition implements EntityDefinition {
  constructor(entityClient) {
    super({ entityClient });
  }

  async authorize(reqData) {
    const { authType } = reqData.payload;

    if (authType !== "user") {
      return false;
    }

    switch (reqData.method) {
      case "find": {
        if (authType === "user") {
          return true;
        }
        return false;
      }
      default: {
        return false;
      }
    }
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @phenyl/standards

Weekly Downloads

152

Version

4.1.0

License

Apache-2.0

Unpacked Size

54.2 kB

Total Files

19

Last publish

Collaborators

  • shinout
  • naturalclar
  • sasurau4
  • wh1tecat
  • bowzstandard
  • alternacrow
  • camcam-lemon
  • 1natsu