Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

TypeError: req.toObject is not a function #908

Open
ToolmanP opened this issue Jun 27, 2023 · 3 comments
Open

TypeError: req.toObject is not a function #908

ToolmanP opened this issue Jun 27, 2023 · 3 comments

Comments

@ToolmanP
Copy link

ToolmanP commented Jun 27, 2023

I was trying to run a ldap server instance referred by the example provided by the ldapjs documentation with Node.js v20.

server.add('ou=users, o=myhost', pre, (req, res, next) => {
...
const entry = req.toObject().attributes;
...
}

Then I tried to invoke this handler by invoking the LDAPAdd provided by the OpenLDAP.

However, the requests fails. I tried to hook up the server with pino logger and this time it provides me with an error message.

{
"msg":"127.0.0.1:57282::1 uncaught exception: TypeError: req.toObject is not a function at Server.<anonymous>..."
}

Is this example out of date in v3 or did I miss something here?

@ToolmanP
Copy link
Author

Ok, I switch the version to v2 and it works correctly.

@jsumners
Copy link
Member

Is this example out of date

Yes. The current equivalent would be entry.pojo.attributes. But it would be better to use the object itself to access the attributes, e.g. entry.attributes.

@advgal
Copy link

advgal commented Sep 22, 2023

The examples/inmemory.js does not work with V3

`server.add(SUFFIX, authorize, function (req, res, next) {
const dn = req.dn.toString()

if (db[dn]) { return next(new ldap.EntryAlreadyExistsError(dn)) }

db[dn] = req.toObject().attributes
res.end()
return next()
})`

does not work. In V3 there is no AddRequest object and no toObject function anymore.

Also the code in http://ldapjs.org/server.html#add is wrong for the same reason.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants