import jwt from 'jsonwebtoken' ; import { getBase64 } from '@contentpi/utils' ; import config from '../../config' ; const { security : { secretKey } } = config ; export function jwtVerify ( accessToken , cb ) { jwt . verify ( accessToken , secretKey , ( error , accessTokenData = { } ) => { const { data : user } = accessTokenData ; if ( error || ! user ) { return cb ( false ) ; } const userData = getBase64 ( user ) ; return cb ( userData ) ; } ) ; } export async function getUserData ( accessToken ) { const UserPromise = new Promise ( resolve => jwtVerify ( accessToken , ( user ) => resolve ( user ) ) ) ; const user = await UserPromise ; return user ; }