I see this snippet:
app.addHook('onRequest', (req, reply, done) => {
// overwrite the defaults
req.requestContext.set('user', { id: 'helloUser' });
done();
});
// this should now get `helloUser` instead of the default `system`
app.get('/', (req, reply) => {
const user = req.requestContext.get('user');
reply.code(200).send( { user });
});
And I wonder: what's the difference from:
app.decorateRequest('user', null);
app.addHook('onRequest', (req, reply, done) => {
// overwrite the defaults
req.user = { id: 'helloUser' }
done();
});
// this should now get `helloUser` instead of the default `system`
app.get('/', (req, reply) => {
const user = req.user;
reply.code(200).send( { user });
});
?
I've used the above in a app that runs in pm2 cluster mode and it seems to work. Does this mean it's currently susceptible to a race condition?