sdelements / lets-chat

Self-hosted chat app for small teams
http://sdelements.github.io/lets-chat
MIT License
9.76k stars 1.58k forks source link

LDAP login throwing Mongoose "schema not registered" #720

Closed Cyberwizzard closed 7 years ago

Cyberwizzard commented 7 years ago

When using the LDAP authentication method, giving an invalid login gives the expected user or password incorrect message.

But when providing a correct login, the server crashes with:

/home/cyberwizzard/node_modules/mongoose/lib/index.js:350
      throw new mongoose.Error.MissingSchemaError(name);
            ^
MissingSchemaError: Schema hasn't been registered for model "User".
Use mongoose.model(name, schema)
    at Mongoose.model (/home/cyberwizzard/node_modules/mongoose/lib/index.js:350:13)
    at Function.Ldap.findOrCreateFromLDAP (/home/cyberwizzard/node_modules/lets-chat-ldap/lib/auth.js:75:25)
    at Ldap.<anonymous> (/home/cyberwizzard/node_modules/lets-chat-ldap/lib/auth.js:69:25)
    at null.<anonymous> (/home/cyberwizzard/node_modules/lets-chat-ldap/node_modules/passport-ldapauth/lib/passport-ldapauth/strategy.js:187:21)
    at /home/cyberwizzard/node_modules/lets-chat-ldap/node_modules/passport-ldapauth/node_modules/ldapauth-fork/lib/ldapauth.js:333:18
    at LdapAuth._getGroups (/home/cyberwizzard/node_modules/lets-chat-ldap/node_modules/passport-ldapauth/node_modules/ldapauth-fork/lib/ldapauth.js:143:14)
    at /home/cyberwizzard/node_modules/lets-chat-ldap/node_modules/passport-ldapauth/node_modules/ldapauth-fork/lib/ldapauth.js:322:12
    at _done (/home/cyberwizzard/node_modules/lets-chat-ldap/node_modules/ldapjs/lib/client/client.js:791:12)
    at messageCallback (/home/cyberwizzard/node_modules/lets-chat-ldap/node_modules/ldapjs/lib/client/client.js:869:16)
    at Parser.onMessage (/home/cyberwizzard/node_modules/lets-chat-ldap/node_modules/ldapjs/lib/client/client.js:199:12)
    at Parser.emit (events.js:107:17)
    at Parser.write (/home/cyberwizzard/node_modules/lets-chat-ldap/node_modules/ldapjs/lib/messages/parser.js:105:8)
    at Socket.onData (/home/cyberwizzard/node_modules/lets-chat-ldap/node_modules/ldapjs/lib/client/client.js:155:24)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:163:16)
    at Socket.Readable.push (_stream_readable.js:126:10)
    at TCP.onread (net.js:540:20)

What is this and how can it be solved?

Cyberwizzard commented 7 years ago

I have not yet used Mongoose or modified Lets Chat but what I found in the documentation is the Mongoose requires defining schemas for standard objects. This error sounds like the plugin is loaded before the "User" schema is registered.

How can this be changed? Perhaps the load order is wrong?

Cyberwizzard commented 7 years ago

This error went away when upgrading to a new platform with all dependencies updated to the newest versions.