extends nodebb write-api?
-
Could you explain what you trying to accomplish?
When you create a POST route using the router parameter sent to a plugin's load hook, the middleware already authenticates the currently logged in user, placing their data in
req.uid
/req.user
. -
First of all: thanks for the answer!
I would like to "expand" the Write API, so using as middleware the one that uses the Bearer Tokens.
I have another server from which I want to post some content automatically and then "apply to this content" the "functionalities" of my plugin.Let's say that the idea is like: I want to create a topic and right after make it a question. Making the topic a "question" is a socket request that only admins can do, so I wanted to create a POST route on my plugin that authenticates with the Bearer Token instead of
req.uid
.If it's not clear I'll try to explain it better
-
If it is just for your own forum, I would rename the write-api plugin. (folder and package name) that you can use the same token system to authenticate. Then create the new routes, It should be straightforward by looking at an existing route. eg And your app would send a request to that route with the bearer token. In your example, you would just be doing the same thing the qa plugin does here with your new tid from the request.
-
@yariplus Mhm so I have to work a little bit on how to mix the two things, because I already have my "personalized QA plugin", I thought that after installing the write-api plugin I could use their middleware, instead I need to copy that into mine plugin.
Thanks for the answer You've been really useful!
-
To anyone searching the same thing, I resolved the problem using the custom write-api hooks, I wasn't aware of:
nodebb-plugin-write-api/routes/v1/index.js at master 路 NodeBB/nodebb-plugin-write-api
A RESTful JSON-speaking API allowing you to write things to NodeBB - nodebb-plugin-write-api/routes/v1/index.js at master 路 NodeBB/nodebb-plugin-write-api
GitHub (github.com)
filter:plugin.write-api.routes
that gives you
data
, I used it in this way:function(data, callback) { var app = data.router; var apiMiddleware = data.apiMiddleware; var middleware = data.middleware; var errorHandler = data.errorHandler; app.post('/route', apiMiddleware.requireUser, function(req, res) { // do stuff }); callback(null, { router: app }); };
Obviously you should have
nodebb-plugin-write-api
installed.