iohptokenadmin
v2.0.0
Published
jwt admin
Downloads
9
Readme
iohptokenadmin
import { decode, verify, sign } from 'jsonwebtoken';
//para mantener la seguridad e la aplicacion pero // sobre todo la independencia esta libreria // que procura crear, validar y parsear un token dado // el SECRET o key esta fuera de ella y la aplicacion // al llamar cualquiera de las funciones de esta libreria // debe proveerlo... asi la podemos exportar hasta para github... //ya que el secret debe ser dado a cada funcion y no esta // pegado en esta libreria......
//retorna true si el token es valido //usada en /api/validadetaccess.json.js // no solo es necesario descomprimir el token si no saber // si es valido , vencido, fecha, el secret.. etc
//string con el token a validar //Descomprime el token devuelve la data del mismo export function validateToken(GTOKEN,secret) { if (GTOKEN) { try { var isval = verify(GTOKEN, secret); return isval; } catch (err) { return false; } } return false; }
//asume que data esta validado y tiene un tokendata.userid //devuelve el token ya generado y encriptado
export function NewTokenObject(tokendata,secret) { if (!tokendata) return '';
const TOKEN = sign(
{
data: tokendata,
},
secret,
{ expiresIn: '12h' },
);
let res = TOKEN;
return res;
}