From b89d0e7dada186e31be37e62a7a75efc2dbe9c99 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 26 Aug 2023 22:29:03 -0700 Subject: feat: initial build --- src/lib/AniList/identity.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/lib/AniList/identity.ts (limited to 'src/lib/AniList/identity.ts') diff --git a/src/lib/AniList/identity.ts b/src/lib/AniList/identity.ts new file mode 100644 index 00000000..a77891d6 --- /dev/null +++ b/src/lib/AniList/identity.ts @@ -0,0 +1,32 @@ +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(); + + return { + id: userIdResponse['data']['Viewer']['id'], + name: userIdResponse['data']['Viewer']['name'] + }; +}; -- cgit v1.2.3