maestro-server/server-app

View on GitHub
app/identity/services/libs/decodePassForgot.js

Summary

Maintainability
A
0 mins
Test Coverage
A
92%
'use strict';

const jwt = require('jwt-simple');
const config = require('identity/config/auth_forgot_config');

const Crypto = require('core/libs/crypto');

const ConflictError = require('core/errors/factoryError')('ConflictError');

module.exports = function (crypto) {

    return new Promise((resolve, reject) => {

        let result, decoded;

        try {
            decoded = jwt.decode(crypto.token, config.jwtSecret.secretOrKey);
        } catch (err) {
            throw new ConflictError(err);
        }

        const string = Crypto.decrypt(decoded);

        try {
            result = JSON.parse(string);
        } catch(err) {
            reject(err);
        }

        resolve(result);

    });
};