import jwt from 'jsonwebtoken';
import { IDToken } from './types';

export const isIDToken = (
  payload: jwt.JwtPayload | string,
): payload is IDToken => {
  if (typeof payload === 'string') return false;
  const token = payload as IDToken;
  if (token.sub === undefined) return false;
  if (token.emails === undefined) return false;
  if (token.exp === undefined) return false;
  if (token.iat === undefined) return false;

  return true;
};
