From 2b4079be438d8bb3b2ac7570ad054b01c3ea3a53 Mon Sep 17 00:00:00 2001 From: ukataria Date: Fri, 9 Feb 2024 11:58:14 -0500 Subject: [PATCH] Final Changes --- package-lock.json | 260 +++++++++++++++++++++++++++++++++++++++++++++- package.json | 5 +- routes/auth.js | 15 +++ 3 files changed, 275 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index bc105e4..57dadb1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,24 +1,168 @@ { - "name": "testinggpt", + "name": "globalex", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "testinggpt", + "name": "globalex", "version": "1.0.0", "license": "ISC", "dependencies": { + "abbrev": "^1.1.1", + "accepts": "^1.3.8", + "agent-base": "^6.0.2", + "ansi-regex": "^5.0.1", + "append-field": "^1.0.0", + "aproba": "^2.0.0", + "are-we-there-yet": "^2.0.0", + "array-flatten": "^1.1.1", + "balanced-match": "^1.0.2", + "base64url": "^3.0.1", "bcrypt": "^5.1.1", "body-parser": "^1.20.2", + "brace-expansion": "^1.1.11", + "bson": "^6.3.0", + "buffer-from": "^1.1.2", + "busboy": "^1.6.0", + "bytes": "^3.1.2", + "call-bind": "^1.0.6", + "chownr": "^2.0.0", + "color-support": "^1.1.3", + "concat-map": "^0.0.1", + "concat-stream": "^1.6.2", + "console-control-strings": "^1.1.0", + "content-disposition": "^0.5.4", + "content-type": "^1.0.5", + "cookie": "^0.5.0", "cookie-session": "^2.1.0", + "cookie-signature": "^1.0.6", + "cookies": "^0.9.1", + "core-util-is": "^1.0.3", "cors": "^2.8.5", + "debug": "^2.6.9", + "define-data-property": "^1.1.2", + "delegates": "^1.0.0", + "depd": "^2.0.0", + "destroy": "^1.2.0", + "detect-libc": "^2.0.2", "dotenv": "^16.4.1", + "ee-first": "^1.1.1", + "emoji-regex": "^8.0.0", + "encodeurl": "^1.0.2", + "es-errors": "^1.3.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", "express": "^4.18.2", + "finalhandler": "^1.2.0", + "forwarded": "^0.2.0", + "fresh": "^0.5.2", + "fs-minipass": "^2.1.0", + "fs.realpath": "^1.0.0", + "function-bind": "^1.1.2", + "gauge": "^3.0.2", + "get-intrinsic": "^1.2.4", + "glob": "^7.2.3", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.1", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "has-unicode": "^2.0.1", + "hasown": "^2.0.0", + "http-errors": "^2.0.0", + "https-proxy-agent": "^5.0.1", + "iconv-lite": "^0.4.24", + "inflight": "^1.0.6", + "inherits": "^2.0.4", + "ipaddr.js": "^1.9.1", + "is-fullwidth-code-point": "^3.0.0", + "isarray": "^1.0.0", + "jsonwebtoken": "^9.0.2", + "kareem": "^2.5.1", + "keygrip": "^1.1.0", + "lru-cache": "^6.0.0", + "make-dir": "^3.1.0", + "media-typer": "^0.3.0", + "memory-pager": "^1.5.0", + "merge-descriptors": "^1.0.1", + "methods": "^1.1.2", + "mime": "^1.6.0", + "mime-db": "^1.52.0", + "mime-types": "^2.1.35", + "minimatch": "^3.1.2", + "minimist": "^1.2.8", + "minipass": "^5.0.0", + "minizlib": "^2.1.2", + "mkdirp": "^1.0.4", + "mongodb": "^6.3.0", + "mongodb-connection-string-url": "^3.0.0", "mongoose": "^8.1.1", + "mpath": "^0.9.0", + "mquery": "^5.0.0", + "ms": "^2.0.0", "multer": "^1.4.5-lts.1", + "negotiator": "^0.6.3", + "node-addon-api": "^5.1.0", + "node-fetch": "^2.7.0", + "nopt": "^5.0.0", + "npmlog": "^5.0.1", + "oauth": "^0.10.0", + "object-assign": "^4.1.1", + "object-inspect": "^1.13.1", + "on-finished": "^2.4.1", + "on-headers": "^1.0.2", + "once": "^1.4.0", + "parseurl": "^1.3.3", "passport": "^0.7.0", - "passport-google-oauth20": "^2.0.0" + "passport-google-oauth20": "^2.0.0", + "passport-oauth2": "^1.8.0", + "passport-strategy": "^1.0.0", + "path-is-absolute": "^1.0.1", + "path-to-regexp": "^0.1.7", + "pause": "^0.0.1", + "process-nextick-args": "^2.0.1", + "proxy-addr": "^2.0.7", + "punycode": "^2.3.1", + "qs": "^6.11.0", + "range-parser": "^1.2.1", + "raw-body": "^2.5.2", + "readable-stream": "^3.6.2", + "rimraf": "^3.0.2", + "safe-buffer": "^5.2.1", + "safer-buffer": "^2.1.2", + "semver": "^7.6.0", + "send": "^0.18.0", + "serve-static": "^1.15.0", + "set-blocking": "^2.0.0", + "set-function-length": "^1.2.1", + "setprototypeof": "^1.2.0", + "side-channel": "^1.0.5", + "sift": "^16.0.1", + "signal-exit": "^3.0.7", + "sparse-bitfield": "^3.0.3", + "statuses": "^2.0.1", + "streamsearch": "^1.1.0", + "string_decoder": "^1.3.0", + "string-width": "^4.2.3", + "strip-ansi": "^6.0.1", + "tar": "^6.2.0", + "toidentifier": "^1.0.1", + "tr46": "^0.0.3", + "tsscmp": "^1.0.6", + "type-is": "^1.6.18", + "typedarray": "^0.0.6", + "uid2": "^0.0.4", + "unpipe": "^1.0.0", + "util-deprecate": "^1.0.2", + "utils-merge": "^1.0.1", + "uuid": "^9.0.1", + "vary": "^1.1.2", + "webidl-conversions": "^3.0.1", + "whatwg-url": "^5.0.0", + "wide-align": "^1.1.5", + "wrappy": "^1.0.2", + "xtend": "^4.0.2", + "yallist": "^4.0.0" } }, "node_modules/@mapbox/node-pre-gyp": { @@ -211,6 +355,11 @@ "node": ">=16.20.1" } }, + "node_modules/buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==" + }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -390,6 +539,11 @@ "node": ">= 0.8" } }, + "node_modules/core-util-is": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" + }, "node_modules/cors": { "version": "2.8.5", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", @@ -465,6 +619,14 @@ "url": "https://github.com/motdotla/dotenv?sponsor=1" } }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -860,6 +1022,51 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" }, + "node_modules/jsonwebtoken": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz", + "integrity": "sha512-PRp66vJ865SSqOlgqS8hujT5U4AOgMfhrwYIuIhfKaoSCZcirrmASQr8CX7cUg+RMih+hgznrjp99o+W4pJLHQ==", + "dependencies": { + "jws": "^3.2.2", + "lodash.includes": "^4.3.0", + "lodash.isboolean": "^3.0.3", + "lodash.isinteger": "^4.0.4", + "lodash.isnumber": "^3.0.3", + "lodash.isplainobject": "^4.0.6", + "lodash.isstring": "^4.0.1", + "lodash.once": "^4.0.0", + "ms": "^2.1.1", + "semver": "^7.5.4" + }, + "engines": { + "node": ">=12", + "npm": ">=6" + } + }, + "node_modules/jsonwebtoken/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/jwa": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.4.1.tgz", + "integrity": "sha512-qiLX/xhEEFKUAJ6FiBMbes3w9ATzyk5W7Hvzpa/SLYdxNtng+gcurvrI7TbACjIXlsJyr05/S1oUhZrc63evQA==", + "dependencies": { + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.2.2.tgz", + "integrity": "sha512-YHlZCB6lMTllWDtSPHz/ZXTsi8S00usEV6v1tjq8tOUZzw7DpSDWVXjXDre6ed1w/pd495ODpHZYSdkRTsa0HA==", + "dependencies": { + "jwa": "^1.4.1", + "safe-buffer": "^5.0.1" + } + }, "node_modules/kareem": { "version": "2.5.1", "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.5.1.tgz", @@ -879,6 +1086,41 @@ "node": ">= 0.6" } }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==" + }, + "node_modules/lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==" + }, + "node_modules/lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==" + }, + "node_modules/lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==" + }, + "node_modules/lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==" + }, + "node_modules/lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==" + }, + "node_modules/lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==" + }, "node_modules/lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -1756,6 +1998,18 @@ "node": ">= 0.4.0" } }, + "node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index 16dcbb3..eee8fda 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "ipaddr.js": "^1.9.1", "is-fullwidth-code-point": "^3.0.0", "isarray": "^1.0.0", + "jsonwebtoken": "^9.0.2", "kareem": "^2.5.1", "keygrip": "^1.1.0", "lru-cache": "^6.0.0", @@ -136,8 +137,8 @@ "sparse-bitfield": "^3.0.3", "statuses": "^2.0.1", "streamsearch": "^1.1.0", - "string-width": "^4.2.3", "string_decoder": "^1.3.0", + "string-width": "^4.2.3", "strip-ansi": "^6.0.1", "tar": "^6.2.0", "toidentifier": "^1.0.1", @@ -149,6 +150,7 @@ "unpipe": "^1.0.0", "util-deprecate": "^1.0.2", "utils-merge": "^1.0.1", + "uuid": "^9.0.1", "vary": "^1.1.2", "webidl-conversions": "^3.0.1", "whatwg-url": "^5.0.0", @@ -157,7 +159,6 @@ "xtend": "^4.0.2", "yallist": "^4.0.0" }, - "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node server.js" diff --git a/routes/auth.js b/routes/auth.js index 1beae4c..cbcde56 100644 --- a/routes/auth.js +++ b/routes/auth.js @@ -1,14 +1,24 @@ // routes/auth.js const express = require('express'); const bcrypt = require('bcrypt'); +const jwt = require('jsonwebtoken'); +const { v4: uuidv4 } = require('uuid'); const User = require('../models/user'); const router = express.Router(); router.post('/register', async (req, res) => { try { const hashedPassword = await bcrypt.hash(req.body.password, 10); + const identity = uuidv4(); const user = new User({ email: req.body.email, password: hashedPassword }); const savedUser = await user.save(); + + const token = jwt.sign( + { userId: savedUser._id, email: savedUser.email }, + process.env.JWT_SECRET, + { expiresIn: '1h' } + ); + res.status(201).send({ message: 'User created', userId: savedUser._id }); } catch (error) { console.error(error); @@ -27,6 +37,11 @@ router.post('/login', async (req, res) => { } try { if (await bcrypt.compare(req.body.password, user.password)) { + const token = jwt.sign( + { userId: user._id, email: user.email }, + process.env.JWT_SECRET, + { expiresIn: '1h' } + ); res.send('Success'); } else { res.send('Not Allowed');