September 2017
Intermediate to advanced
450 pages
11h 24m
English
One of the trickiest parts of working with authentication is debugging it. Luckily, we can update our custom Morgan logging middleware to log details about authenticated user behaviors.
By adding custom tokens for email and role, we can automatically log these properties on authenticated requests. We can also provide the callback skip to Morgan to tell it to only log requests that have an authorized user session on them already:
var fs = require('fs');var path = require('path');var JSONAPIError = require('jsonapi-serializer').Error;module.exports = { logger: function(morgan, filename) { if (!filename) filename = 'admin.log'; var adminLogFilePath = path.resolve(__dirname, "../", filename); var adminLogStream = fs.createWriteStream(adminLogFilePath ...
Read now
Unlock full access