rajt
Version:
A serverless bundler layer, fully typed for AWS Lambda (Node.js and LLRT) and Cloudflare Workers.
27 lines (20 loc) • 580 B
text/typescript
import { Authnz } from './authnz'
import { Token } from './token'
export class Auth {
static #u: Authnz<any> | null = null
static resolve() {
this.#u = Authnz.fromToken(Token.fromRequest())
}
static get user() {
return this.#u ? this.#u?.data : null
}
static can(...abilities: string[]): boolean {
return this.#u ? this.#u.can(...abilities) : false
}
static cant(...abilities: string[]): boolean {
return !this.can(...abilities)
}
static hasRole(...roles: string[]): boolean {
return this.#u ? this.#u.hasRole(...roles) : false
}
}