@phenyl/standards
v4.1.0
Published
Standards has templates for user definition.
Downloads
698
Keywords
Readme
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;
}
}
}
}