diff --git a/backend/package-lock.json b/backend/package-lock.json index ea3dc6f..bcbada7 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -120,9 +120,9 @@ } }, "node_modules/@babel/core/node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "dev": true, "license": "MIT", "dependencies": { @@ -555,9 +555,9 @@ } }, "node_modules/@babel/traverse": { - "version": "7.26.3", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.26.3.tgz", - "integrity": "sha512-yTmc8J+Sj8yLzwr4PD5Xb/WF3bOYu2C2OoSZPzbuqRm4n98XirsbzaX+GloeO376UnSYIYJ4NCanwV5/ugZkwA==", + "version": "7.26.4", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.26.4.tgz", + "integrity": "sha512-fH+b7Y4p3yqvApJALCPJcwb0/XaOSgtK4pzV6WVjPR5GLFQBRI7pfoX2V2iM48NXvX07NUxxm1Vw98YjqTcU5w==", "dev": true, "license": "MIT", "dependencies": { @@ -574,9 +574,9 @@ } }, "node_modules/@babel/traverse/node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "dev": true, "license": "MIT", "dependencies": { @@ -1115,6 +1115,7 @@ "integrity": "sha512-9JgOaunvQdsQ/qW2OPmE5+hCeUB52lQSolecrFrthct55QekhmXEwT203s20RL+UHtCQc15y3VXpby9E7Kkh/g==", "deprecated": "This is a stub types definition. axios provides its own type definitions, so you do not need this installed.", "dev": true, + "license": "MIT", "dependencies": { "axios": "*" } @@ -1231,13 +1232,13 @@ } }, "node_modules/@types/form-data": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-2.5.2.tgz", - "integrity": "sha512-tfmcyHn1Pp9YHAO5r40+UuZUPAZbUEgqTel3EuEKpmF9hPkXgR4l41853raliXnb4gwyPNoQOfvgGGlHN5WSog==", - "deprecated": "This is a stub types definition. form-data provides its own type definitions, so you do not need this installed.", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-2.2.1.tgz", + "integrity": "sha512-JAMFhOaHIciYVh8fb5/83nmuO/AHwmto+Hq7a9y8FzLDcC1KCU344XDOMEmahnrTFlHjgh4L0WJFczNIX2GxnQ==", "dev": true, + "license": "MIT", "dependencies": { - "form-data": "*" + "@types/node": "*" } }, "node_modules/@types/graceful-fs": { @@ -1537,9 +1538,9 @@ } }, "node_modules/agent-base/node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -2026,16 +2027,15 @@ } }, "node_modules/call-bind": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", - "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.8.tgz", + "integrity": "sha512-oKlSFMcMwpUg2ednkhQ454wfWiU/ul3CkJe/PEHcTKuiX6RpbehUiFMXu13HalGZxfUwCQzZG747YXBn1im9ww==", "license": "MIT", "dependencies": { + "call-bind-apply-helpers": "^1.0.0", "es-define-property": "^1.0.0", - "es-errors": "^1.3.0", - "function-bind": "^1.1.2", "get-intrinsic": "^1.2.4", - "set-function-length": "^1.2.1" + "set-function-length": "^1.2.2" }, "engines": { "node": ">= 0.4" @@ -2044,6 +2044,19 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.0.tgz", + "integrity": "sha512-CCKAP2tkPau7D3GE8+V8R6sQubA9R5foIzGp+85EXCVSCivuxBNAWqcpn72PKYiIcqoViv/kcUDpaEIMBVi1lQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -2065,9 +2078,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001686", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001686.tgz", - "integrity": "sha512-Y7deg0Aergpa24M3qLC5xjNklnKnhsmSyR/V89dLZ1n0ucJIFNs7PgR2Yfa/Zf6W79SbBicgtGxZr2juHkEUIA==", + "version": "1.0.30001687", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001687.tgz", + "integrity": "sha512-0S/FDhf4ZiqrTUiQ39dKeUjYRjkv7lOZU1Dgif2rIqrTzX/1wV2hfKu9TOm1IHkdSijfLswxTFzl/cvir+SLSQ==", "dev": true, "funding": [ { @@ -2638,6 +2651,20 @@ "url": "https://dotenvx.com" } }, + "node_modules/dunder-proto": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.0.tgz", + "integrity": "sha512-9+Sj30DIu+4KvHqMfLUGLFYL2PkURSYMVXJyXe92nFRvlYq5hBjLEhblKB+vkd/WVlUYMWigiY07T91Fkk0+4A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/ecdsa-sig-formatter": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", @@ -2670,9 +2697,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.68", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.68.tgz", - "integrity": "sha512-FgMdJlma0OzUYlbrtZ4AeXjKxKPk6KT8WOP8BjcqxWtlg8qyJQjRzPJzUtUn5GBg1oQ26hFs7HOOHJMYiJRnvQ==", + "version": "1.5.71", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.71.tgz", + "integrity": "sha512-dB68l59BI75W1BUGVTAEJy45CEVuEGy9qPVVQ8pnHyHMn36PLPPoE1mjLH+lo9rKulO3HC2OhbACI/8tCqJBcA==", "dev": true, "license": "ISC" }, @@ -2728,13 +2755,10 @@ } }, "node_modules/es-define-property": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", - "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", "license": "MIT", - "dependencies": { - "get-intrinsic": "^1.2.4" - }, "engines": { "node": ">= 0.4" } @@ -2907,6 +2931,7 @@ "version": "4.21.2", "resolved": "https://registry.npmjs.org/express/-/express-4.21.2.tgz", "integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==", + "license": "MIT", "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", @@ -3272,16 +3297,19 @@ } }, "node_modules/get-intrinsic": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", - "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.5.tgz", + "integrity": "sha512-Y4+pKa7XeRUPWFNvOOYHkRYrfzW07oraURSvjDmRVOJ748OrVmeXtpE4+GCEHncjCjkTxPNRt8kEbxDhsn6VTg==", "license": "MIT", "dependencies": { + "call-bind-apply-helpers": "^1.0.0", + "dunder-proto": "^1.0.0", + "es-define-property": "^1.0.1", "es-errors": "^1.3.0", "function-bind": "^1.1.2", - "has-proto": "^1.0.1", - "has-symbols": "^1.0.3", - "hasown": "^2.0.0" + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2" }, "engines": { "node": ">= 0.4" @@ -3407,13 +3435,10 @@ } }, "node_modules/gopd": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.1.0.tgz", - "integrity": "sha512-FQoVQnqcdk4hVM4JN1eromaun4iuS34oStkdlLENLdpULsuQcTyXj8w7ayhuUfPwEYZ1ZOooOTT6fdA9Vmx/RA==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", "license": "MIT", - "dependencies": { - "get-intrinsic": "^1.2.4" - }, "engines": { "node": ">= 0.4" }, @@ -3450,21 +3475,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/has-proto": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.1.0.tgz", - "integrity": "sha512-QLdzI9IIO1Jg7f9GT1gXpPpXArAn6cS31R1eEZqz08Gc+uQ8/XiqHWt17Fiw+2p6oTTIq5GXEpQkAlA88YRl/Q==", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.7" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/has-symbols": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", @@ -3556,9 +3566,9 @@ } }, "node_modules/http-proxy-agent/node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "dev": true, "license": "MIT", "dependencies": { @@ -3594,9 +3604,9 @@ } }, "node_modules/https-proxy-agent/node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -3929,9 +3939,9 @@ } }, "node_modules/istanbul-lib-source-maps/node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "dev": true, "license": "MIT", "dependencies": { @@ -4924,9 +4934,9 @@ } }, "node_modules/mailgun-js/node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -5256,6 +5266,7 @@ "version": "8.8.4", "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.8.4.tgz", "integrity": "sha512-yJbn695qCsqDO+xyPII29x2R7flzXhxCDv09mMZPSGllf0sm4jKw3E9s9uvQ9hjO6bL2xjU8KKowYqcY9eSTMQ==", + "license": "MIT", "dependencies": { "bson": "^6.7.0", "kareem": "2.6.3", @@ -5377,9 +5388,9 @@ } }, "node_modules/mquery/node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -5530,9 +5541,9 @@ } }, "node_modules/nodemon/node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -5799,9 +5810,9 @@ } }, "node_modules/pac-proxy-agent/node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -5981,7 +5992,8 @@ "node_modules/path-to-regexp": { "version": "0.1.12", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz", - "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==" + "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==", + "license": "MIT" }, "node_modules/picocolors": { "version": "1.1.1", @@ -6138,9 +6150,9 @@ } }, "node_modules/proxy-agent/node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "license": "MIT", "dependencies": { "ms": "^2.1.3" diff --git a/backend/src/app.ts b/backend/src/app.ts index d9df694..5e5b10a 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -7,7 +7,6 @@ import { connectDB } from './config/database' import cors from 'cors'; import helmet from 'helmet'; import morgan from 'morgan'; -import { authenticatedLimiter, limiter } from './utils/rateLimiting'; const app = express(); @@ -30,9 +29,6 @@ app.use('/api/auth', authRoutes); app.use('/api/snippets', snippetRoutes); -app.use(limiter); // Aplicando o rate limiter -app.use('/api', authenticatedLimiter) // Aplicando o rate limiter apenas para rotas autenticadas - // Passando uma mensagem dinâmica para o middleware de erro app.use((req: Request, res: Response, next: NextFunction): void => { res.status(404).json({ message: 'Rota não encontrada' }); diff --git a/backend/src/controllers/authController.ts b/backend/src/controllers/authController.ts index a7252b3..073ee68 100644 --- a/backend/src/controllers/authController.ts +++ b/backend/src/controllers/authController.ts @@ -91,7 +91,7 @@ export const loginUser = async (req: Request, res: Response, next: NextFunction) // Verifica se o usuário está bloqueado if (user.isLocked()) { - return handleValidationError(res, 'Conta bloqueada devido a várias tentativas de login. Tente novamente mais tarde.'); + return handleValidationError(res, 'Conta bloqueada devido a várias tentativas de login. Tente novamente mais tarde.'); } const isMatch = await user.comparePassword(password); diff --git a/backend/src/routes/authRoutes.ts b/backend/src/routes/authRoutes.ts index 04e729f..69be999 100644 --- a/backend/src/routes/authRoutes.ts +++ b/backend/src/routes/authRoutes.ts @@ -3,6 +3,7 @@ import { registerUser, loginUser, forgotPassword, resetPassword } from '../contr import { body } from 'express-validator'; import { ValidationChain, Result, validationResult } from 'express-validator'; import { validateResetToken } from '../middlewares/validateResetToken'; +import { limiter } from '../utils/rateLimiting'; // Criando um method switch para validação de campos interface ValidationMethod { @@ -68,14 +69,14 @@ const asyncHandler = (fn: Function) => (req: any, res: any, next: any) => { const router = Router(); // Rotas para usuários -router.post('/register', validate('register'), validateRequest, asyncHandler(registerUser)); // Registro de um novo usuário +router.post('/register', validate('register'), limiter, validateRequest, asyncHandler(registerUser)); // Registro de um novo usuário -router.post('/login', validate('login'), validateRequest, asyncHandler(loginUser)); // Login de usuário +router.post('/login', validate('login'), limiter, validateRequest, asyncHandler(loginUser)); // Login de usuário // Rotas de forgot e reset password -router.post('/forgot-password', validate('forgot-password'), validateRequest, asyncHandler(forgotPassword)); // Solicitação de redefinição de senha +router.post('/forgot-password', limiter, validate('forgot-password'), validateRequest, asyncHandler(forgotPassword)); // Solicitação de redefinição de senha -router.post('/reset-password/:token', validateResetToken, validate('reset-password'), validateRequest, asyncHandler(resetPassword)); +router.post('/reset-password/:token', limiter, validateResetToken, validate('reset-password'), validateRequest, asyncHandler(resetPassword)); router.use((err: any, req: Request, res: Response, next: NextFunction): void => { diff --git a/backend/src/routes/snippetRoutes.ts b/backend/src/routes/snippetRoutes.ts index c8f6a81..2c0998e 100644 --- a/backend/src/routes/snippetRoutes.ts +++ b/backend/src/routes/snippetRoutes.ts @@ -13,53 +13,54 @@ import { fetchSharedSnippet, shareSnippet, } from '../controllers/snippetController'; +import { authenticatedLimiter, limiter } from '../utils/rateLimiting'; const router = Router(); // Rotas para snippets -router.get('/public-snippets', validateToken, (req, res, next) => { +router.get('/public-snippets', authenticatedLimiter, validateToken, (req, res, next) => { fetchPublicSnippets(req, res, next).catch(next); // Propaga erros ao middleware }); // Busca snippets públicos -router.post('/create-snippets', validateToken, (req, res, next) => { +router.post('/create-snippets', authenticatedLimiter, validateToken, (req, res, next) => { createSnippet(req, res, next).catch(next); }); // Criação de um novo snippet -router.get('/my-snippets', validateToken, (req, res, next) => { +router.get('/my-snippets', authenticatedLimiter, validateToken, (req, res, next) => { fetchMySnippets(req, res, next).catch(next); }); // Busca snippets do usuário -router.get('/my-favorites', validateToken, (req, res, next) => { +router.get('/my-favorites', authenticatedLimiter, validateToken, (req, res, next) => { fetchMySnippetsFavorite(req, res, next).catch(next); }); // Busca snippets favoritos do usuário -router.get('/search', validateToken, (req, res, next) => { +router.get('/search', authenticatedLimiter, validateToken, (req, res, next) => { fetchPublicSnippets(req, res, next).catch(next); }); // Busca snippets por termo -router.get('/tags', validateToken, (req, res, next) => { +router.get('/tags', authenticatedLimiter, validateToken, (req, res, next) => { fetchPublicSnippets(req, res, next).catch(next); }); // Busca snippets por tag -router.get('/shared/:link', fetchSharedSnippet); // Busca snippets compartilhados com o usuário +router.get('/shared/:link', limiter, fetchSharedSnippet); // Busca snippets compartilhados com o usuário -router.post('/:id/share', validateToken, (req, res, next) => { +router.post('/:id/share', authenticatedLimiter, validateToken, (req, res, next) => { shareSnippet(req, res, next).catch(next); }); // Compartilha um snippet -router.put('/:id', validateToken, (req, res, next) => { +router.put('/:id', authenticatedLimiter, validateToken, (req, res, next) => { updateSnippet(req, res, next).catch(next); }); // Atualização de um snippet existente -router.delete('/:id', validateToken, (req, res, next) => { +router.delete('/:id', authenticatedLimiter, validateToken, (req, res, next) => { deleteSnippet(req, res, next).catch(next); }); // Exclusão de um snippet -router.get('/:id', validateToken, (req, res, next) => { +router.get('/:id', authenticatedLimiter, validateToken, (req, res, next) => { getSnippet(req, res, next).catch(next); }); // Busca um snippet específico -router.patch('/:id/favorite', validateToken, (req, res, next) => { +router.patch('/:id/favorite', authenticatedLimiter, validateToken, (req, res, next) => { markFavorite(req, res, next).catch(next); }); // Marca ou desmarca como favorito diff --git a/backend/src/server.ts b/backend/src/server.ts index 8d3a7b7..0278ca2 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -1,5 +1,6 @@ import app from './app'; import env from './config/env'; +import './types/'; const PORT = env.PORT || ''; diff --git a/backend/src/types/index.ts b/backend/src/types/index.ts new file mode 100644 index 0000000..6a448f1 --- /dev/null +++ b/backend/src/types/index.ts @@ -0,0 +1,11 @@ +import { Request } from 'express'; + +declare module 'express-serve-static-core' { + interface Request { + user?: { + id: string; + name?: string; + email?: string; + }; + } +} diff --git a/backend/src/types/types/index.d.ts b/backend/src/types/types/index.d.ts deleted file mode 100644 index 2e60aaa..0000000 --- a/backend/src/types/types/index.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare namespace Express { - export interface Request { - user?: { - id: string; - }; - } -} diff --git a/backend/src/utils/rateLimiting.ts b/backend/src/utils/rateLimiting.ts index d2ed8d1..1e5e414 100644 --- a/backend/src/utils/rateLimiting.ts +++ b/backend/src/utils/rateLimiting.ts @@ -10,6 +10,6 @@ export const limiter = rateLimit({ // Limite de requisições por usuário autenticado export const authenticatedLimiter = rateLimit({ windowMs: 15 * 60 * 1000, // 15 minutos - max: 500, // 500 requisições + max: 500, message: 'Você atingiu o limite de requisições. Por favor, tente novamente em 15 minutos.', }); diff --git a/backend/tsconfig.json b/backend/tsconfig.json index b2155d6..36499eb 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -1,29 +1,18 @@ { "compilerOptions": { - /* Language and Environment */ - "target": "ES2020", // Define a versão ECMAScript para o código gerado. - "module": "commonjs", // Sistema de módulos padrão para Node.js. - "lib": ["ES2020"], // Inclui declarações para ES2020. - "esModuleInterop": true, // Permite importação de módulos ES6 como CommonJS. - "forceConsistentCasingInFileNames": true, // Garante consistência de capitalização em nomes de arquivos. - - /* Modules */ - "moduleResolution": "node", // Resolve módulos como o Node.js. - "resolveJsonModule": true, // Permite a importação de módulos JSON. - - /* Typo Roots */ - "typeRoots": ["./node_modules/@types", "./src/types"], // Caminho para as definições de tipo. - - /* Emit */ - "outDir": "./dist", // Define o diretório de saída para arquivos compilados. - "rootDir": "./src", // Define o diretório raiz para os arquivos TypeScript. - "types": ["jest"], // Inclui tipos de teste do Jest. - "sourceMap": true, // Gera arquivos de mapa de origem para depuração. - - /* Type Checking */ - "strict": true, // Habilita todas as verificações de tipo estritas. - "skipLibCheck": true // Ignora a verificação de tipo em arquivos de declaração (.d.ts). + "target": "ES2020", + "module": "commonjs", + "lib": ["ES2020"], + "strict": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "moduleResolution": "node", + "typeRoots": ["./node_modules/@types", "./src/types"], // Certifique-se disso! + "resolveJsonModule": true, + "outDir": "./dist", + "rootDir": "./src", + "skipLibCheck": true }, - "include": ["src/**/*"], // Inclui apenas a pasta 'src' para compilação. - "exclude": ["node_modules", "dist"] // Exclui 'node_modules' e 'dist' da compilação. + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] }