diff options
| author | Ivan Chen <ivan@thetaggid.com> | 2020-10-27 19:31:39 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-27 19:31:39 -0400 |
| commit | 795ba089207571ec13226f2d07c149c8697763ce (patch) | |
| tree | 81d08094396cda3195287fa0c72c5cb4c91a1287 /src/services/SocialLinkingService.ts | |
| parent | e004fd362583a020b07f87536aac077269eaad27 (diff) | |
done (#81)
Diffstat (limited to 'src/services/SocialLinkingService.ts')
| -rw-r--r-- | src/services/SocialLinkingService.ts | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/src/services/SocialLinkingService.ts b/src/services/SocialLinkingService.ts index 8d67d90e..c9ffcedf 100644 --- a/src/services/SocialLinkingService.ts +++ b/src/services/SocialLinkingService.ts @@ -20,21 +20,50 @@ export const integratedEndpoints: {[social: string]: [string, string]} = { Twitter: [LINK_TWITTER_OAUTH, LINK_TWITTER_ENDPOINT], }; -export const nonIntegratedEndponits: {[social: string]: string} = { +export const nonIntegratedEndpoints: {[social: string]: string} = { Snapchat: LINK_SNAPCHAT_ENDPOINT, TikTok: LINK_TIKTOK_ENDPOINT, }; +export const getNonIntegratedURL: ( + socialType: string, + userId: string, +) => Promise<string> = async (socialType, userId) => { + if (!(socialType in nonIntegratedEndpoints)) { + return ''; + } + try { + const userToken = await AsyncStorage.getItem('token'); + const response = await fetch( + nonIntegratedEndpoints[socialType] + userId + '/', + { + method: 'GET', + headers: { + Authorization: `Token ${userToken}`, + }, + }, + ); + if (response.status !== 200) { + throw 'Unable to fetch profile URL:' + socialType; + } + const body = await response.json(); + return body.url || ''; + } catch (error) { + console.log(error); + return ''; + } +}; + export const registerNonIntegratedSocialLink: ( socialType: string, username: string, ) => Promise<boolean> = async (socialType, username) => { - if (!(socialType in nonIntegratedEndponits)) { + if (!(socialType in nonIntegratedEndpoints)) { return false; } try { const user_token = await AsyncStorage.getItem('token'); - const response = await fetch(nonIntegratedEndponits[socialType], { + const response = await fetch(nonIntegratedEndpoints[socialType], { method: 'POST', headers: { Authorization: `Token ${user_token}`, |
