1.0.169 • Published 9 months ago

fireback-tools v1.0.169

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

Fireback tools

This package contains the typescript definitions, grpc definitions, sdk, and other necessary tools to use fireback in JavaScript world:

  • GRPC Definitions in typescript (web/nodejs)
  • GRPC Definitions in javascript (web/nodejs)
  • Fireback sdk for web and react native
  • Pure Typescript interfaces, without extra code

Fireback is a software that helps developers to build user-authentication flow as a microservice, it provides rich set of HTTP, CLI, GRPC tools to signup users, manage permissions and so on.

Note for beginners

This library is only for communicating with fireback, you need to install the module separately. Download it from https://pixelplux.com/en/fireback/downloads for Windows, Linux, Mac, Android and other platforms

Using fireback-tools for front-end, and calling grpc

npm i --save fireback-tools
yarn add fireback-tools

Using fireback-tools for nestjs

Here we will be exploring how to integrate the nestjs project with a fireback authentication. This integration is quite simple, but if you want to use it in production you need to learn about permissions, User role workspace model of the fireback to manage the permissions on real-life examples.

Note: You can add fireback to existing nestjs project, or new one. It does not need changes to your setup, or coding style, etc.

Make sure you have installed fireback

Fireback is a binary product, you need to download and install it on your computer/server, and run it like a webserver in order to use it. This article shows only how to integrate fireback into nestjs project, meaning expects you already have installed fireback, and it runs on http://localhost:4500 using fireback start command.

Install the fireback-tools

npm i fireback-tools --save

Or for yarn users:

yarn add fireback-tools

This will install the necessary tools to work with fireback on Node.js, React, Angular, Nestjs. Also it provides typedefinitions of internal structure. Basically everything related to fireback.

Set environment variables

This step is optional, if you did not change the port of fireback.

You need to set two environment variables: FIREBACK_HOSTNAME and FIREABACK_PORT. For example:

FIREBACK_HOSTNAME=example.com FIREBACK_PORT=6700 npm start

Add FirebackModule to your app.module.ts

Open your app.module.ts in nest project, and add the FirebackModule into the modules section. It's a dynamic module, you need to call register function.

import { Module } from "@nestjs/common";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";

// + Line below is needed
import { FirebackModule } from "fireback-tools/nestjs";

@Module({
  imports: [
    // + Line below is needed
    FirebackModule.register(),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Now you have the fireback available in your nest project.

Add WithWorkspace to each route

Adding FirebackModule doesn't have any effect by itself, and you need to specifiy the WithWorkspace guard for those endpoints you want to be authenticated.

WithWorkspace can accept strings as argument (not an array), and will pass those permissions directly to the Fireback server for validation.

As an example, we just make sure this route is authenticated:

import { Controller, Get, Req, Res, UseGuards } from '@nestjs/common';
import { AppService } from './app.service';

// + Line below is needed to import fireback classes
import { AuthResult, WithWorkspace } from 'fireback-tools/nestjs';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}


  @Get()
  @UseGuards(WithWorkspace('EXAMPLE_PERMISSION_1'))
  getHello(@Req() req: { name: string } & AuthResult) {

    /**
     * Now this req also has the AuthResult, see response result for fields.
     * You can check the username, permissions, access level with this object.
     */
    return { auth: req.auth };
  }
}

The result of the endpoint would be something like this. You do not want to send the object into response, use the information here while creating entities or querying the entities.

Create a new user using fireback cli, or http, then add the token as authorization while calling your nestjs api, and it will show you:

{
  "auth": {
    "workspaceId": "b9cdb1e8",
    "internalSql": "workspace_id in (\"b9cdb1e8\")",
    "userId": "7eadec94",
    "user": {
      "uniqueId": "7eadec94"
    },
    "accessLevel": {
      "capabilities": ["*"],
      "workspaces": ["b9cdb1e8"],
      "sql": "workspace_id in (\"b9cdb1e8\")"
    }
  }
}

Conclusion

Now you have added authentication for your nestjs. You can create user with fireback API, you do not need to wrap all routes from fireback into your project. It means, your app would be running on port :3000, it's completely your code, but if you want to signup user, you would call passport/email/signup on port :4500 directly to fireback.

Next steps

You configurated the nestjs and fireback, but also you need to know few things more to be compatible real world requirements.

  • Understand how to define permissions in your fireback project.
  • Understand how to create your entities, and which data you need to put while creating your database

Links

Download the fireback:

https://pixelplux.com/en/fireback

1.0.169

9 months ago

1.0.165

10 months ago

1.0.164

10 months ago

1.0.167

10 months ago

1.0.166

10 months ago

1.0.161

11 months ago

1.0.160

11 months ago

1.0.163

10 months ago

1.0.162

10 months ago

1.0.168

10 months ago

1.0.156

11 months ago

1.0.155

11 months ago

1.0.158

11 months ago

1.0.157

11 months ago

1.0.159

11 months ago

1.0.143

12 months ago

1.0.142

12 months ago

1.0.145

12 months ago

1.0.144

12 months ago

1.0.141

12 months ago

1.0.140

12 months ago

1.0.147

12 months ago

1.0.149

12 months ago

1.0.148

12 months ago

1.0.139

12 months ago

1.0.154

11 months ago

1.0.153

11 months ago

1.0.152

11 months ago

1.0.151

12 months ago

1.0.132

1 year ago

1.0.131

1 year ago

1.0.134

1 year ago

1.0.133

1 year ago

1.0.130

1 year ago

1.0.135

1 year ago

1.0.101

1 year ago

1.0.100

1 year ago

1.0.107

1 year ago

1.0.109

1 year ago

1.0.108

1 year ago

1.0.103

1 year ago

1.0.102

1 year ago

1.0.105

1 year ago

1.0.104

1 year ago

1.0.121

1 year ago

1.0.123

1 year ago

1.0.129

1 year ago

1.0.128

1 year ago

1.0.124

1 year ago

1.0.126

1 year ago

1.0.88

1 year ago

1.0.89

1 year ago

1.0.110

1 year ago

1.0.112

1 year ago

1.0.111

1 year ago

1.0.117

1 year ago

1.0.119

1 year ago

1.0.113

1 year ago

1.0.116

1 year ago

1.0.115

1 year ago

1.0.91

1 year ago

1.0.90

1 year ago

1.0.94

1 year ago

1.0.92

1 year ago

1.0.99

1 year ago

1.0.97

1 year ago

1.0.96

1 year ago

1.0.62

1 year ago

1.0.61

1 year ago

1.0.60

1 year ago

1.0.66

1 year ago

1.0.65

1 year ago

1.0.64

1 year ago

1.0.63

1 year ago

1.0.69

1 year ago

1.0.68

1 year ago

1.0.67

1 year ago

1.0.73

1 year ago

1.0.71

1 year ago

1.0.70

1 year ago

1.0.77

1 year ago

1.0.76

1 year ago

1.0.75

1 year ago

1.0.37

1 year ago

1.0.79

1 year ago

1.0.35

1 year ago

1.0.78

1 year ago

1.0.34

1 year ago

1.0.39

1 year ago

1.0.38

1 year ago

1.0.80

1 year ago

1.0.84

1 year ago

1.0.40

1 year ago

1.0.83

1 year ago

1.0.81

1 year ago

1.0.44

1 year ago

1.0.87

1 year ago

1.0.43

1 year ago

1.0.86

1 year ago

1.0.42

1 year ago

1.0.85

1 year ago

1.0.48

1 year ago

1.0.46

1 year ago

1.0.45

1 year ago

1.0.49

1 year ago

1.0.51

1 year ago

1.0.50

1 year ago

1.0.54

1 year ago

1.0.52

1 year ago

1.0.59

1 year ago

1.0.58

1 year ago

1.0.56

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago