@foal/typeorm

Last updated 9 days ago

Table of contents

index.ts

Functions

PermissionRequired

Hook factory to check if a user can access a route based on their permissions.

This function uses UserWithPermissions.hasPerm under the hood. It is very likely that you have to use the fetchUserWithPermissions function when using this hook.

function PermissionRequired(perm: string, options: { redirect?: string | undefined; } = {}): HookDecorator;

Parameters

Name

Type

Default value

Description

perm

string

- The name of the permission.

options

{ redirect?: string | undefined; }

{}

- Hook options.

Return type

HookDecorator

fetchUserWithPermissions

Create a function that finds the first entity that matches some id. Groups and permissions are also retreived so that UserWithPermissions.hasPerm and PermissionRequired can be used.

It returns undefined if no entity can be found.

This function is usually used by:

  • LoginRequired (@foal/core)

  • LoginOptional (@foal/core)

  • JWTRequired (@foal/jwt)

  • JWTOptional (@foal/jwt)

function fetchUserWithPermissions(userEntityClass: Class<{ id: number | string; }>): (id: number | string) => Promise<any>;

Parameters

Name

Type

Description

userEntityClass

Class<{ id: number | string; }>

- The entity class which must extend UserWithPermissions.

Return type

(id: number | string) => Promise

fetchUser

Create a function that finds the first entity that matches some id.

It returns undefined if no entity can be found.

This function is usually used by:

  • LoginRequired (@foal/core)

  • LoginOptional (@foal/core)

  • JWTRequired (@foal/jwt)

  • JWTOptional (@foal/jwt)

function fetchUser(userEntityClass: Class<{ id: number | string; }>): (id: number | string) => Promise<any>;

Parameters

Name

Type

Description

userEntityClass

Class<{ id: number | string; }>

- The entity class.

Return type

(id: number | string) => Promise

Classes

Abstract class to define a user entity with a system of groups and permissions.

A group can have permissions. A user can have permissions and belong to groups that have also permissions.

Group

Entity representing a group. A group can have permissions.

[Permission][ClassDeclaration-2]

Entity representing a permission.

[ClassDeclaration-2]: index/permission.md#permission