aboutsummaryrefslogtreecommitdiff
path: root/src/lib/AniList/identity.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-08-26 22:29:03 -0700
committerFuwn <[email protected]>2023-08-26 22:29:03 -0700
commitb89d0e7dada186e31be37e62a7a75efc2dbe9c99 (patch)
tree8c9f6b5d7aa0f709c06d5eb45fbf763883b21c89 /src/lib/AniList/identity.ts
downloaddue.moe-b89d0e7dada186e31be37e62a7a75efc2dbe9c99.tar.xz
due.moe-b89d0e7dada186e31be37e62a7a75efc2dbe9c99.zip
feat: initial build
Diffstat (limited to 'src/lib/AniList/identity.ts')
-rw-r--r--src/lib/AniList/identity.ts32
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']
+ };
+};