{"info":{"_postman_id":"bee25c48-b494-4e3e-af50-29db28d0e836","name":"User Authentication and Authorization using Bearer Token","description":"<html><head></head><body><p>Here we are using 8 different API Calls for various process like creation, login, logout and getting information of the users.</p>\n</body></html>","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","toc":[],"owner":"38692959","collectionId":"bee25c48-b494-4e3e-af50-29db28d0e836","publishedId":"2sAYBUDsEf","public":true,"customColor":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"FF6C37"},"publishDate":"2024-11-24T19:40:56.000Z"},"item":[{"name":"Create New User (or) Register User","id":"4f0bd49e-8ce2-47c4-9c80-1738a38d8334","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[],"body":{"mode":"raw","raw":"{\r\n        \"name\": \"Jack Martinez\",\r\n        \"email\": \"jack.martinez@example.com\",\r\n        \"password\": \"123456789\",\r\n        \"dateOfBirth\": \"1994-01-19\",\r\n        \"role\": \"user\",\r\n        \"createdAt\": \"2023-10-01T07:30:00Z\"\r\n    }","options":{"raw":{"language":"json"}}},"url":"{{base_uri}}/auth/register","description":"<p><strong>Register a User</strong>: Send a POST request to <code>/api/v1/auth/register</code> with JSON payload containing username, email, and password.</p>\n","urlObject":{"path":["auth","register"],"host":["{{base_uri}}"],"query":[],"variable":[]}},"response":[],"_postman_id":"4f0bd49e-8ce2-47c4-9c80-1738a38d8334"},{"name":"Login","id":"adc1e475-40f5-4c86-a26e-a0f1ecd2c9d2","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[],"body":{"mode":"raw","raw":"{\r\n    \"email\":\"krish@gmail.com\",\r\n    \"password\":\"123456789\"\r\n}","options":{"raw":{"language":"json"}}},"url":"{{base_uri}}/auth/login","description":"<p><code>POST /api/v1/auth/login</code> <strong>Login User</strong>: Send a POST request to <code>/api/v1/auth/login</code> with username and password. You’ll receive a JWT if credentials are valid.</p>\n","urlObject":{"path":["auth","login"],"host":["{{base_uri}}"],"query":[],"variable":[]}},"response":[],"_postman_id":"adc1e475-40f5-4c86-a26e-a0f1ecd2c9d2"},{"name":"Log Out","id":"a68d13be-2c11-4344-b887-35aa63a4f568","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[],"url":"{{base_uri}}/auth/logout","description":"<p><code>POST api/v1/auth/logout</code> <strong>Logout User</strong>: Send a POST request to <code>api/v1/auth/logout</code>. It clears the token which is stored in the browser and logged out from the browser. If it is logged out, then we can't use the protected route <code>api/v1/auth/me</code></p>\n","urlObject":{"path":["auth","logout"],"host":["{{base_uri}}"],"query":[],"variable":[]}},"response":[],"_postman_id":"a68d13be-2c11-4344-b887-35aa63a4f568"},{"name":"Get All Users","id":"02b8a844-a813-4c14-aeb4-6f512fc2a31c","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"auth":{"type":"bearer","bearer":{"basicConfig":[{"key":"token","value":"<token>"}]},"isInherited":false},"method":"GET","header":[],"url":"{{base_uri}}/auth/users","description":"<p>This is used to get information of all the users. Only accessible by admin module.</p>\n<p><code>GET api/v1/auth/users</code> <strong>Access Protected Routes - All Informations of the Users</strong> : Send a get request to <code>api/v1/auth/users</code> with <code>Authorization: bearer token</code> header after logging in. If it is already logged in with <code>role:admin</code>, it returns all the informations of the registered users. Else it prevents the users to get all informations.</p>\n","urlObject":{"path":["auth","users"],"host":["{{base_uri}}"],"query":[],"variable":[]}},"response":[],"_postman_id":"02b8a844-a813-4c14-aeb4-6f512fc2a31c"},{"name":"User Information","id":"8bde09f1-7120-4563-a6c6-2c09e3a32e45","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"auth":{"type":"bearer","bearer":{"basicConfig":[{"key":"token","value":"<token>"}]},"isInherited":false},"method":"GET","header":[],"url":"{{base_uri}}/auth/me","description":"<p>It is used to get the information about the user.</p>\n","urlObject":{"path":["auth","me"],"host":["{{base_uri}}"],"query":[],"variable":[]}},"response":[],"_postman_id":"8bde09f1-7120-4563-a6c6-2c09e3a32e45"},{"name":"Home","id":"90c8fb9d-4aeb-4bb9-91eb-1ba93f38385e","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"auth":{"type":"bearer","bearer":{"basicConfig":[{"key":"token","value":"<token>"}]},"isInherited":false},"method":"GET","header":[],"url":"{{base_uri}}/auth/home","description":"<p><code>GET /api/v1/auth/home</code> <strong>Home URL</strong> : It shows basic form to log in and testing the APIs mentioned in the 3rd and 5th APIs. Remaining APIs can be checked using POSTMAN. <code>/api/v1/auth/home</code></p>\n","urlObject":{"path":["auth","home"],"host":["{{base_uri}}"],"query":[],"variable":[]}},"response":[],"_postman_id":"90c8fb9d-4aeb-4bb9-91eb-1ba93f38385e"},{"name":"Update User","id":"85e62572-1618-4f09-bb3f-dd0e231e3613","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"auth":{"type":"bearer","bearer":{"basicConfig":[{"key":"token","value":"<token>"}]},"isInherited":false},"method":"PUT","header":[],"body":{"mode":"raw","raw":"{\r\n  \"name\":\"Brown Boss\",\r\n  \"email\": \"newemail@example.com\",\r\n  \"dateOfBirth\": \"1995-01-01\",\r\n  \"role\": \"user\"\r\n}\r\n","options":{"raw":{"language":"json"}}},"url":"{{base_uri}}/auth/users/67437b495d011fa12c4a7ca0","description":"<p><code>PUT /api/v1/auth/users/:id</code> <strong>Update User</strong> : To Update the user, we can use their id. Since it is a protected route, we could only access them after admin login.</p>\n","urlObject":{"path":["auth","users","67437b495d011fa12c4a7ca0"],"host":["{{base_uri}}"],"query":[],"variable":[]}},"response":[],"_postman_id":"85e62572-1618-4f09-bb3f-dd0e231e3613"},{"name":"Delete User","id":"c360439f-236a-4303-a1e9-585e24bf2e0d","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"DELETE","header":[],"url":"{{base_uri}}/auth/users/67437b495d011fa12c4a7ca0","description":"<p><code>DELETE /api/v1/auth/users/:id</code> <strong>Delete an User</strong> : Using the ID of an user, we can delete the user by admin login.</p>\n","urlObject":{"path":["auth","users","67437b495d011fa12c4a7ca0"],"host":["{{base_uri}}"],"query":[],"variable":[]}},"response":[],"_postman_id":"c360439f-236a-4303-a1e9-585e24bf2e0d"}]}