diff options
Diffstat (limited to 'src/lib/AniList/identity.ts')
| -rw-r--r-- | src/lib/AniList/identity.ts | 32 |
1 files changed, 32 insertions, 0 deletions
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<UserIdentity> => { + 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'] + }; +}; |