1005913c0b
* Encrypts all notes going to the database * Creates encrypted snippets for loading note title cards * Creates an encrypted search index when note is changed * Migrates users to encrypted notes on login * Creates new encrypted master keys for newly logged in users
26 lines
591 B
JavaScript
26 lines
591 B
JavaScript
var jwt = require('jsonwebtoken');
|
|
|
|
let Auth = {}
|
|
|
|
const tokenSecretKey = process.env.JSON_KEY
|
|
|
|
Auth.createToken = (userId, masterKey) => {
|
|
const signedData = {'id':userId, 'date':Date.now(), 'masterKey':masterKey}
|
|
const token = jwt.sign(signedData, tokenSecretKey)
|
|
return token
|
|
}
|
|
Auth.decodeToken = (token) => {
|
|
return new Promise((resolve, reject) => {
|
|
jwt.verify(token, tokenSecretKey, function(err, decoded){
|
|
if(err || decoded.id == undefined){
|
|
reject('Bad Token')
|
|
return
|
|
}
|
|
//Pass back decoded token
|
|
resolve(decoded)
|
|
return
|
|
});
|
|
})
|
|
}
|
|
|
|
module.exports = Auth |