{"size": 734, "ext": "js", "max_stars_repo_path": "src/lib/jwt.js", "max_stars_repo_name": "dolchi21/open-prices", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/lib/jwt.js", "max_issues_repo_name": "dolchi21/open-prices", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lib/jwt.js", "max_forks_repo_name": "dolchi21/open-prices", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.6774193548, "max_line_length": 81, "alphanum_fraction": 0.621253406}
import store from '../stores/variables'

var jwt = require('express-jwt')
var jsonwebtoken = require('jsonwebtoken')


store.set('jwt_secret', Math.random() + '')


export function sign(data, options = {}) {
    var secret = store.get('jwt_secret')
    return jsonwebtoken.sign(data, secret, options)
}
export function decode(jwt) {
    return jsonwebtoken.decode(jwt)
}
export function middleware(options = {}) {
    
    var opts = Object.assign({
        secret: store.get('jwt_secret'),
        getToken: req => {
            var token = req.cookies.accessToken
            var hToken = (req.headers.authorization || '').replace('Bearer ', '')
            return token || hToken
        }
    }, options)

    return jwt(opts)

}
