diff options
| author | Fuwn <[email protected]> | 2024-02-08 00:01:24 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-02-08 00:01:24 -0800 |
| commit | f78f5f4857f24ee5338fb1643c666a6b18d75769 (patch) | |
| tree | 57b1b09f20b6b261a3b1ae15bfa441965f71ecd9 /src/lib/Data/AniList/identity.ts | |
| parent | refactor(data): move static data to module (diff) | |
| download | due.moe-f78f5f4857f24ee5338fb1643c666a6b18d75769.tar.xz due.moe-f78f5f4857f24ee5338fb1643c666a6b18d75769.zip | |
refactor(anilist): move to data module
Diffstat (limited to 'src/lib/Data/AniList/identity.ts')
| -rw-r--r-- | src/lib/Data/AniList/identity.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib/Data/AniList/identity.ts b/src/lib/Data/AniList/identity.ts new file mode 100644 index 00000000..7214ffa4 --- /dev/null +++ b/src/lib/Data/AniList/identity.ts @@ -0,0 +1,34 @@ +export interface UserIdentity { + id: number; + name: string; + avatar: 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 avatar { large } } }` }) + }) + ).json(); + + return { + id: userIdResponse['data']['Viewer']['id'], + name: userIdResponse['data']['Viewer']['name'], + avatar: userIdResponse['data']['Viewer']['avatar']['large'] + }; +}; |