Skip to content

Commit 0964b44

Browse files
authored
Merge pull request #3 from payloadcms/feature/allow-undefined-collections
feat: allows undefined collections
2 parents bd92b0a + afbc8a4 commit 0964b44

File tree

4 files changed

+419
-479
lines changed

4 files changed

+419
-479
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,11 @@
194194
"@types/terser-webpack-plugin": "^5.0.2",
195195
"@types/testing-library__jest-dom": "^5.9.5",
196196
"@types/uuid": "^8.3.0",
197-
"@types/webpack": "4.41.25",
197+
"@types/webpack": "4.41.26",
198198
"@types/webpack-bundle-analyzer": "^3.9.0",
199-
"@types/webpack-dev-middleware": "^3.7.2",
199+
"@types/webpack-dev-middleware": "4.0.0",
200200
"@types/webpack-env": "^1.15.3",
201-
"@types/webpack-hot-middleware": "^2.25.3",
201+
"@types/webpack-hot-middleware": "2.25.3",
202202
"@typescript-eslint/eslint-plugin": "^4.8.1",
203203
"@typescript-eslint/parser": "4.0.1",
204204
"babel-eslint": "^10.0.1",

src/collections/init.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ export default function registerCollections(ctx: Payload): void {
2727
const { maxLoginAttempts, lockTime } = collection.auth;
2828

2929
if (maxLoginAttempts > 0) {
30+
type LoginSchema = {
31+
loginAttempts: number
32+
lockUntil: number
33+
isLocked: boolean
34+
};
35+
3036
// eslint-disable-next-line func-names
31-
schema.methods.incLoginAttempts = function (cb) {
37+
schema.methods.incLoginAttempts = function (this: mongoose.Document<any> & LoginSchema, cb) {
3238
// Expired lock, restart count at 1
3339
if (this.lockUntil && this.lockUntil < Date.now()) {
3440
return this.updateOne({
@@ -37,7 +43,6 @@ export default function registerCollections(ctx: Payload): void {
3743
}, cb);
3844
}
3945

40-
type LoginSchema = { loginAttempts: number; };
4146
const updates: UpdateQuery<LoginSchema> = { $inc: { loginAttempts: 1 } };
4247
// Lock the account if at max attempts and not already locked
4348
if (this.loginAttempts + 1 >= maxLoginAttempts && !this.isLocked) {

src/config/defaults.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'path';
33
export const defaults = {
44
defaultDepth: 2,
55
maxDepth: 10,
6+
collections: [],
67
globals: [],
78
cookiePrefix: 'payload',
89
csrf: [],

0 commit comments

Comments
 (0)