2.2.1 • Published 2 years ago

@nest-firebase/security v2.2.1

Weekly downloads
37
License
MIT
Repository
github
Last release
2 years ago

@nest-firebase/security

Description

This module provides protection to actions/queries through decorators.

Installation

$ npm install --save @nest-firebase/security

Methods

NameDescription.env
@isUser()Acccepts an array of string roles and validate if token is valid and user has one of the requested roles to proceed. If no role is informed, it only check if token belongs to a valid userUSER_AUTH_URL
@isClient()Use google-auth-library to verify the integrity of the ID tokenOAUTH_AUDIENCE
@CurrentUser()Get a payload with token owner data.

Usage

Just annotate yout REST actions and Graphql queries/mutations methods with decorator.

The client should send a Bearer authorization header e.g., 'Authorization: Bearer JWT_TOKEN'.

You can also use the @CurrentUser param annotation to get access to the current user.

  1. Add USER_AUTH_URL or OAUTH_AUDIENCE to .env
USER_AUTH_URL='https://knowledge-staging.skore.io/workspace/v1/users/current'
OAUTH_AUDIENCE='https://test.skore.io'
  1. Import the decorator and have fun
import { IsUser, CurrentUser } from '@nest-firebase/security'

@Controller('users')
export class UserController {
  @IsUser(['admin', 'expert'])
  @Get()
  async hello(@CurrentUser() user: any): string {
    return user.companyId
  }
}
2.2.1

2 years ago

2.0.3

3 years ago

2.1.1

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.1.0

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.9.1

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.2

3 years ago

1.7.0

3 years ago

1.7.4

3 years ago

1.5.10

4 years ago

1.5.9

4 years ago

1.5.5

4 years ago

1.5.8

4 years ago

1.5.7

4 years ago

1.5.6

4 years ago

1.5.4

4 years ago

1.5.3

4 years ago

1.5.2

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago