Installations
npm install @exobase/use-role-authorization
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Node Version
18.19.1
NPM Version
lerna/8.1.2/node@v18.19.1+arm64 (darwin)
Score
69.7
Supply Chain
86
Quality
79.5
Maintenance
100
Vulnerability
99.3
License
Releases
Unable to fetch releases
Love this project? Help keep it running — sponsor us today! 🚀
Download Statistics
Total Downloads
16,092
Last Day
14
Last Week
26
Last Month
126
Last Year
2,213
Bundle Size
31.96 kB
Minified
7.62 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.0-rc.14
Package Id
@exobase/use-role-authorization@1.0.0-rc.14
Unpacked Size
14.71 kB
Size
4.24 kB
File Count
17
NPM Version
lerna/8.1.2/node@v18.19.1+arm64 (darwin)
Node Version
18.19.1
Publised On
08 Jul 2024
Total Downloads
Cumulative downloads
Total Downloads
16,092
Last day
180%
14
Compared to previous day
Last week
100%
26
Compared to previous week
Last month
-5.3%
126
Compared to previous month
Last year
-83.5%
2,213
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
title: 'useRoleAuthorization' description: 'A role authorization hook' group: 'Hooks' badge: 'Auth'
Exobase hook to check if a request is authorized given the roles that are attached to it.
Install
1yarn add @exobase/use-role-authorization 2# or 3yarn add @exobase/hooks
Import
1import { useRoleAuthorization } from '@exobase/use-role-authorization' 2// or 3import { useRoleAuthorization } from '@exobase/hooks'
Usage
1import { compose } from 'radash' 2import type { Props } from '@exobase/core' 3import { useNext } from '@exobase/use-next' 4import { useRoleAuthorization, useTokenAuth } from '@exobase/hooks' 5import type { TokenAuth } from '@exobase/hooks' 6 7type Args = { 8 id: string 9 price: number 10} 11 12type Services = { 13 db: Database 14} 15 16export const updateListing = async ({ 17 args, 18 services 19}: Props<Args, Services, TokenAuth>) => { 20 const { id, price } = args 21 const { db } = services 22 await db.listings.update(id, { price }) 23} 24 25export default compose( 26 useNext(), 27 useJsonBody(z => ({ 28 id: z.string(), 29 price: z.number() 30 })), 31 useTokenAuth(config.auth.tokens.secret), 32 useRoleAuthorization<Props<Args, {}, TokenAuth>>({ 33 roles: ({ auth }) => auth.token.roles, 34 require: 'admin' 35 }), 36 useServices<Services>({ 37 db: () => new Database() 38 }) 39 updateListing 40)
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No security vulnerabilities found.