1.2.0 • Published 1 year ago

hemiron-auth v1.2.0

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
1 year ago

Example usage

To use the hemiron-auth package with your backend you need to install the package with npm:

npm i hemiron-auth

Or with yarn

yarn add hemiron-auth

Then you need to import the AuthenticationValidatorModule in your app.module.ts file:

@Module({
    imports: [
        AuthenticationValidatorModule.setup({
            authenticationServerURL: 'http://manager-3.inf-hsleiden:3000'
        })
    ],
    controllers: [
        ExampleController
    ],
    providers: [
        // apply the authentication guard to every route
        {
            provide: APP_GUARD,
            useClass: AuthenticationValidationGuard,
        },
    ]
})
export class AppModule {}

You are done! If you have troubling using checkout the following example repository (https://github.com/lukasvdberk/hemiron-authenticator-example).

Extracting user from the request

If you want to get the user making the current request, you can use the AuthenticationValidationService to get the user from the request.

@Controller('')
export class ExampleController {
    constructor(
        private readonly authenticationService: AuthenticationService
    ) {}

    @Get('user')
    async getUserFromRequest(@Request() httpRequest: Request) {
        const userMakingRequest = await this.authenticationService.getUserFromRequest(httpRequest)
        console.log(userMakingRequest.id); // unique user id
    }
}

Publishing a new package version

Increment the version number in the package.json file and run the following command to publish the package to the npm registry:

NOTE: Make sure you are logged in to the npm with the npm cli.

./publish-npm.package.sh

Development project

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.