export interface UserIdentity { id: number; name: string; } export interface AniListAuthorisation { tokenType: string; accessToken: string; expiresIn: number; refreshToken: string; } export const userIdentity = async ( anilistAuthorisation: AniListAuthorisation ): Promise => { const userIdResponse = await ( await fetch('https://graphql.anilist.co', { method: 'POST', headers: { Authorization: `${anilistAuthorisation.tokenType} ${anilistAuthorisation.accessToken}`, 'Content-Type': 'application/json', Accept: 'application/json' }, body: JSON.stringify({ query: `{ Viewer { id name } }` }) }) ).json(); console.log(userIdResponse['data']['Viewer']['name']); return { id: userIdResponse['data']['Viewer']['id'], name: userIdResponse['data']['Viewer']['name'] }; };