import axios , { AxiosResponse } from 'axios' ; import { Payload } from '../types/payload' ; import { User } from '../types/user' ; const jwtDecode = require ( 'jwt-decode' ) ; export async function validateToken ( token ) { try { const response = await axios . get ( 'http://localhost:3000/users/authstate' , { headers : { Authorization : `Bearer ${ token }` , 'Content-Type' : 'application/json' , } , } ) ; return response . status == 200 ? true : false ; } catch ( err ) { return false ; } } export async function getUserInformation ( email ) { try { const response = await axios . get ( `http://localhost:3000/users/email/${ email }` , { } ) ; return response . data ; } catch ( err ) { return err ; } } export async function getPayloadFromToken ( token ) { return jwtDecode ( token ) ; } export async function isVerified ( email ) { const user = await getUserInformation ( email ) ; return ! user . verified ? false : user . verified ; }