Giter Club home page Giter Club logo

Comments (13)

noamichael avatar noamichael commented on September 14, 2024 2

Another thought I had is that maybe the schema.js file should simply export the raw JSON of the schema instead, and we can completely remove mongoose as a dependency and let the user import whichever version they want to use:

const ExpressBrute = require('express-brute');
const MongooseStore = require('express-brute-mongoose');
const BruteForceSchema = require('express-brute-mongoose/dist/schema');
const mongoose = require('mongoose');

const model = mongoose.model('bruteforce', new mongoose.Schema(BruteForceSchema));

const store = new MongooseStore(model);

module.exports = new ExpressBrute(store);

from express-brute-mongoose.

noamichael avatar noamichael commented on September 14, 2024 1

I created pull request #14 which should hopefully fix this issue. As a temporary workaround, you can just create the schema with the correct mongoose version yourself:

const ExpressBrute = require('express-brute');
const MongooseStore = require('express-brute-mongoose');
const BruteForceSchema = require('express-brute-mongoose/dist/schema');
const mongoose = require('mongoose');

const bruteForceSchema = new mongoose.Schema(//use our mongoose instance to create the schema
    {
        _id: { type: String },
        data: {
            count: Number,
            lastRequest: Date,
            firstRequest: Date
        },
        expires: { type: Date, index: { expires: '1d' } }
    },
    { collection: 'bruteforce' }
);

const model = mongoose.model('bruteforce', bruteForceSchema);

const store = new MongooseStore(model);

module.exports = new ExpressBrute(store);

from express-brute-mongoose.

MohammedAl-Mahdawi avatar MohammedAl-Mahdawi commented on September 14, 2024 1

Same issue here, fixed it by replacing

var BruteForceSchema = require('express-brute-mongoose/dist/schema');

with

var BruteForceSchema = {
  "_id": String,
  "data": {
    "count": Number,
    "lastRequest": Date,
    "firstRequest": Date
  },
  "expires": Date
}

from express-brute-mongoose.

cbargren avatar cbargren commented on September 14, 2024

Haven't seen that before. What does the code for your schema look like and what version of mongoose are you running in your app?

from express-brute-mongoose.

josh-g3 avatar josh-g3 commented on September 14, 2024

Full app code:

import express from 'express';
import ExpressBrute from 'express-brute';
import MongooseStore from 'express-brute-mongoose';
import BruteForceSchema from 'express-brute-mongoose/dist/schema';
import mongoose from 'mongoose';

let
  app = express(),
  model = mongoose.model('bruteforce', BruteForceSchema),
  store = new MongooseStore(model),
  bruteforce = new ExpressBrute(store);

app.post(
  '/auth',
  bruteforce.prevent,
  (req, res, next) => {
    res.send('Success!');
  }
);

app.listen(3000, () => {
  console.info('Express app listening on port 3000...');
});

Express v4.16.2
Mongo v3.6.1
Mongoose v5.0.1

e: Updated Mongoose to 5.0.2 and same error. Using nodemon & babel too, if that makes a difference.

from express-brute-mongoose.

cbargren avatar cbargren commented on September 14, 2024

Hm... I'm sorry, but I'm not able to repro that locally, even using all those module versions. Could you provide a link to the repository perhaps?

from express-brute-mongoose.

josh-g3 avatar josh-g3 commented on September 14, 2024

Just sent you a private repo invite on BB. Thanks for looking into this for me.

from express-brute-mongoose.

cbargren avatar cbargren commented on September 14, 2024

Alright, I pinned the problem down to the app locking to an outdated version of kareem, which is a dependency of mongoose. I have no idea why it's doing that though... I'll have more time to look into it later in the week.

from express-brute-mongoose.

modermo avatar modermo commented on September 14, 2024

I just ran into this myself... basically followed the standard install.

from express-brute-mongoose.

mkilp avatar mkilp commented on September 14, 2024

I ran into this problem aswell.
Fixed it by ensuring that mongoose is connected to my database before creating the brute storage.

from express-brute-mongoose.

filipporampado avatar filipporampado commented on September 14, 2024

Having the same problem. Checking if mongoose is connected does not work for me. Changing BruteForceSchema to the one provided in the readme and not "express-brute-mongoose/dist/schema", works.

from express-brute-mongoose.

n0bit avatar n0bit commented on September 14, 2024

I am getting this error. I tried waiting for mongoose to connect and changing the default schema to readme schema, but error persist.

Edit:
It works for me now. I had to make a new schema from scratch using the template in readme.

from express-brute-mongoose.

cbargren avatar cbargren commented on September 14, 2024

Thanks for all your guys' input (and sorry for the radio silence). I've implemented @noamichael's suggestion of removing the mongoose dependency from the package altogether and just expect the user to create the schema themselves using a raw json object exported by the package via express-brute-mongoose/dist/schema. That's now live as of v1.1.0. Thanks and open a new issue if anyone's still having problems. 🍻

from express-brute-mongoose.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.