Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wealthbar/authz

Package Overview
Dependencies
Maintainers
4
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wealthbar/authz

helpers for implementing permission checks

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

authz

Short for Authorization (which is "can I" as opposed to Authentication which is "who am I").

authz functions

type authzType = (ctx: authzCtxType) => boolean

An authz function takes a context (see next section) and returns either true if authorization is granted, or false is not.

authz context

type authzCtxType = {
  permissions: {
    [name: string]: boolean,
  },
  user?: {
    id?: string,
  }
};

An authz context contains information about the current authorized user (their id), and the permissions they currently have.

anon

anon always returns true, i.e. everyone is authorized, even those without a user id.

anyUser

anyUser returns true for any user. i.e. any logged in users are authorized; sessions without a user id are not.

anyOf(permissions: string[]): authzType

anyOf generates an authz function that will return true for users with any of the permissions past in the permissions array.

allOf(permissions: string[]): authzType

allOf generates an authz function that will return true for users with all of the permissions past in the permissions array.

anyOfAuthz(authzs: authzType[]): authzType

anyOfAuthz generates an authz function that will return true for users when any of the authz functions past in the authzs array return true.

allOfAuthz(authzs: authzType[]): authzType

allOfAuthz generates an authz function that will return true for users when all of the authz functions past in the authzs array return true.

Example

import {authz} from "@wealthbar/authz"

const hasAandBorC = authz.anyOfAuthz([authz.allOf(["A", "B"]), authz.anyOf(["C"])]);

hasAandBorC requires a user with permissions to both "A" and "B" or permission to "C".

Keywords

FAQs

Package last updated on 26 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc