Skip to content

Repository files navigation

auth-jwt

Nest.JS, Authorization with JSON Web Tokens (JWT), Nest.JS, only Backend.

Script for table in Postgres - Schema: "user",

CREATE TABLE "user"."user" (
	id bigserial NOT NULL,
	firstname varchar(50) NOT NULL DEFAULT ''::character varying,
	lastname varchar(100) NOT NULL DEFAULT ''::character varying,
	email varchar(100) NOT NULL,
	mypassword varchar(400) NOT NULL DEFAULT ''::character varying,
	secret2fa varchar(150) NULL,
	status int2 NOT NULL DEFAULT 0,
	CONSTRAINT pk_user PRIMARY KEY (id)
);

Instructions

npm install
npm install bcrypt // for encryption password
npm run start:dev

Tests

npm run test -t user.controller

EndPoint Postman - Status Verify

GET http://127.0.0.1:3010/api/status
Result

{
    "status": 200,
    "message": "Servicios ejecutandose!"
}

EndPoint Postman - Create User

POST http://127.0.0.1:3010/api/users
Body-Json

{
    "firstname": "juancito",
    "lastname": "pinto",
    "email": "[email protected]",
    "mypassword": "a1b2c3d4"
}

Result

{
    "statusCode": 200,
    "message": "Datos devueltos correctamente.",
    "response": {
        "id": "9",
        "firstname": "juancito",
        "lastname": "pinto",
        "email": "[email protected]",
        "status": 0
    }
}

EndPoint Postman - Login

POST http://127.0.0.1:3010/api/login
Body-Json

{
    "email": "[email protected]",
    "mypassword": "a1b2c3d4"
}

Result

{
    "statusCode": 200,
    "message": "Datos devueltos correctamente.",
    "response": {
        "id": "9",
        "email": "[email protected]",
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjkiLCJpYXQiOjE2NTU4MjcyNjQsImV4cCI6MTY1NTg1NjA2NH0.QN_5RENZDk5hlaIKdEfOdR0b-D0Tx3D8-AoSUHSoIiI"
    }
}

EndPoint Postman - Get Users List

GET http://127.0.0.1:3010/api/users
Headers
KEY: Authorization
VALUE: Token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjkiLCJpYXQiOjE2NTU4MjcyNjQsImV4cCI6MTY1NTg1NjA2NH0.QN_5RENZDk5hlaIKdEfOdR0b-D0Tx3D8-AoSUHSoIiI
Result

{
    "statusCode": 200,
    "message": "Datos devueltos correctamente.",
    "response": [
        {
            "id": "9",
            "firstname": "juancito",
            "lastname": "pinto",
            "email": "[email protected]",
				...
}

For Support

About

Authorization with JSON Web Tokens (JWT), Nest.JS, Backend

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages