Skip to content

Commit

Permalink
Merge pull request #592 from Real-Dev-Squad/develop
Browse files Browse the repository at this point in the history
Dev to Main Sync PR
  • Loading branch information
iamitprakash committed Apr 11, 2024
2 parents 501f5dc + ca64f89 commit 3b4caaf
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 3b4caaf

Please sign in to comment.