diff options
Diffstat (limited to 'src/lib/Data')
| -rw-r--r-- | src/lib/Data/AniList/identity.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/lib/Data/AniList/identity.ts b/src/lib/Data/AniList/identity.ts index eacc2ae4..973e1184 100644 --- a/src/lib/Data/AniList/identity.ts +++ b/src/lib/Data/AniList/identity.ts @@ -34,3 +34,17 @@ export const userIdentity = async ( avatar: userIdResponse["data"]["Viewer"]["avatar"]["large"], }; }; + +export const safeUserIdentity = async ( + anilistAuthorisation: AniListAuthorisation, +): Promise<UserIdentity | null> => { + try { + const identity = await userIdentity(anilistAuthorisation); + + if (!identity.id || !identity.name || !identity.avatar) return null; + + return identity; + } catch { + return null; + } +}; |