Skip to content

Commit

Permalink
Refactor : Updated API for verifying external-account (#588)
Browse files Browse the repository at this point in the history
Co-authored-by: Prakash Choudhary <34452139+prakashchoudhary07@users.noreply.github.com>
  • Loading branch information
ardourApeX and prakashchoudhary07 committed Apr 4, 2024
1 parent 9abed4e commit 5e2a825
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions app/controllers/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@ 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 || '';
@tracked linkStatus = 'not-linked';
@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;
}
Expand All @@ -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';
Expand Down

0 comments on commit 5e2a825

Please sign in to comment.