auth/middleware/ProviderRegistrationEnabled.js

/**
 * @module flitter-auth/middleware/ProviderRegistrationEnabled
 */

const Middleware = require('libflitter/middleware/Middleware')

/**
 * Redirects the user to the login page if the registration page
 * for a particular auth provider is not enabled.
 * @extends module:libflitter/middleware/Middleware~Middleware
 */
class ProviderRegistrationEnabled extends Middleware {

    /**
     * Run the middleware test. If the auth provider's registration is not enabled,
     * redirect the user to the './login' route.
     * @param {express/request} - the request
     * @param {express/response} - the response
     * @return {Promise<*>}
     */
    async test(req, res, next, args = {}){
        
        if ( !req.auth_provider.config.registration ) return res.redirect('./login')
        else return next()
        
    }
}

module.exports = ProviderRegistrationEnabled