From 5e2a825b53b3305fb756247c299cd51f35cef8c4 Mon Sep 17 00:00:00 2001 From: Joy <56365512+ardourApeX@users.noreply.github.com> Date: Thu, 4 Apr 2024 23:41:30 +0530 Subject: [PATCH] Refactor : Updated API for verifying external-account (#588) Co-authored-by: Prakash Choudhary <34452139+prakashchoudhary07@users.noreply.github.com> --- app/controllers/discord.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/app/controllers/discord.js b/app/controllers/discord.js index 0f247ec8..452617d0 100644 --- a/app/controllers/discord.js +++ b/app/controllers/discord.js @@ -6,6 +6,7 @@ import { tracked } from '@glimmer/tracking'; import { action } from '@ember/object'; export default class DiscordController extends Controller { + @service router; @service toast; @tracked discordId = this.model.externalAccountData.attributes.discordId || ''; @@ -13,6 +14,15 @@ export default class DiscordController extends Controller { @tracked isLinking = false; @tracked consent = false; + @tracked token = ''; + + queryParams = { + token: { refreshModel: true }, + }; + + async model() { + this.token = this.paramsFor('discord').token; + } @action setConsent() { this.consent = !this.consent; } @@ -22,14 +32,16 @@ export default class DiscordController extends Controller { this.isLinking = true; if (this.consent) { - const response = await fetch(`${ENV.BASE_API_URL}/users/self`, { - method: 'PATCH', - body: JSON.stringify({ discordId: this.discordId }), - headers: { - 'Content-Type': 'application/json', - }, - credentials: 'include', - }); + const response = await fetch( + `${ENV.BASE_API_URL}/external-accounts/link/${this.token}`, + { + method: 'PATCH', + headers: { + 'Content-Type': 'application/json', + }, + credentials: 'include', + } + ); if (response.status === 204) { this.linkStatus = 'linked';