Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
fix: egvault auth not included
Browse files Browse the repository at this point in the history
  • Loading branch information
TroyKomodo committed Oct 25, 2024
1 parent 1e47f58 commit 7042b2d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 20 deletions.
16 changes: 13 additions & 3 deletions src/views/store/StorePurchase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ const checkout = async () => {
const fd = JSON.parse(formData.value);
const giftQuery = gift && recipient.value ? `&gift_for=${recipient.value.id}` : "";
const store = useStore();
const resp = await fetch(
`${EgVault.api}/v1/subscriptions?renew_interval=${renewInterval}&payment_method=${selectedMethod.value}&next=true${giftQuery}`,
{
Expand All @@ -141,9 +143,17 @@ const checkout = async () => {
},
}),
credentials: "include",
headers: {
"Content-Type": "application/json",
},
headers: (() => {
const headers: HeadersInit = {
"Content-Type": "application/json",
};
if (store.authToken) {
headers["Authorization"] = `Bearer ${store.authToken}`;
}
return headers;
})(),
},
);
if (!resp || !resp.ok) {
Expand Down
52 changes: 49 additions & 3 deletions src/views/store/egvault.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineStore } from "pinia";
import { useDataLoaders } from "@/store/dataloader";
import { useStore } from "@/store/main";
import { useModal } from "@/store/modal";
import type { User } from "@/structures/User";
import ModalError from "@/components/modal/ModalError.vue";
Expand Down Expand Up @@ -79,8 +80,15 @@ export const useEgVault = defineStore("egvault", {
},
actions: {
async fetchSub(): Promise<SubscriptionResponse> {
const store = useStore();

const resp = await fetch(`${EgVault.api}/v1/subscriptions/@me`, {
credentials: "include",
headers: store.authToken
? {
Authorization: `Bearer ${store.authToken}`,
}
: {},
});
const sub: SubscriptionResponse = await resp.json();

Expand All @@ -94,8 +102,15 @@ export const useEgVault = defineStore("egvault", {
return sub;
},
async fetchProducts(): Promise<Product[]> {
const store = useStore();

const response = await fetch(EgVault.api + "/v1/products", {
credentials: "include",
headers: store.authToken
? {
Authorization: `Bearer ${store.authToken}`,
}
: {},
});
const products = await response.json();

Expand All @@ -104,9 +119,16 @@ export const useEgVault = defineStore("egvault", {
},

async cancelSub(): Promise<Response> {
const store = useStore();

const resp = await fetch(`${EgVault.api}/v1/subscriptions/@me`, {
method: "DELETE",
credentials: "include",
headers: store.authToken
? {
Authorization: `Bearer ${store.authToken}`,
}
: {},
});
if (!resp.ok) {
this.showError(resp);
Expand All @@ -117,9 +139,16 @@ export const useEgVault = defineStore("egvault", {
},

async reactivateSub(): Promise<Response> {
const store = useStore();

const resp = await fetch(`${EgVault.api}/v1/subscriptions/@me/reactivate`, {
method: "POST",
credentials: "include",
headers: store.authToken
? {
Authorization: `Bearer ${store.authToken}`,
}
: {},
});
if (!resp.ok) {
this.showError(resp);
Expand All @@ -130,9 +159,16 @@ export const useEgVault = defineStore("egvault", {
},

async updatePayment(): Promise<Response> {
const store = useStore();

const resp = await fetch(`${EgVault.api}/v1/subscriptions/@me/payment-method?next=true`, {
method: "PATCH",
credentials: "include",
headers: store.authToken
? {
Authorization: `Bearer ${store.authToken}`,
}
: {},
});
if (!resp.ok) {
this.showError(resp);
Expand All @@ -143,13 +179,23 @@ export const useEgVault = defineStore("egvault", {
},

async redeemCode(code: string): Promise<Response> {
const store = useStore();

const resp = await fetch(`${EgVault.api}/v1/redeem`, {
method: "POST",
body: JSON.stringify({ code }),
credentials: "include",
headers: {
"Content-Type": "application/json",
},
headers: (() => {
const headers: HeadersInit = {
"Content-Type": "application/json",
};

if (store.authToken) {
headers["Authorization"] = `Bearer ${store.authToken}`;
}

return headers;
})(),
});
if (!resp.ok) {
this.showError(resp);
Expand Down
38 changes: 24 additions & 14 deletions src/views/user/UserEntitlementModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import TextInput from "@/components/form/TextInput.vue";
import Toggle from "@/components/form/Toggle.vue";
import ModalBase from "@/components/modal/ModalBase.vue";
import { BadgeDef, getBadgeByID } from "@/components/utility/BadgeDefs";
import { useStore } from "../../store/main";
const PaintComponent = defineAsyncComponent(() => import("@/components/utility/Paint.vue"));
Expand All @@ -116,17 +117,16 @@ const objectRef = ref<string>("");
const assignable = computed<{ badges: BadgeDef[]; paints: Paint[] }>(() => {
return {
badges:
[
...new Map(
(props.cosmetics.badges ?? [])
?.filter((b) => !props.owned.badges.some((b2) => b.tag === b2.id))
.map((badge) => getBadgeByID(badge.tag, badge.id, badge))
.filter((x) => x?.refID)
.filter((x) => !x?.name || x?.name.toLowerCase().includes(filter.value.toLowerCase()))
.map((b) => [b!.id, b!]),
).values(),
] ?? [],
badges: [
...new Map(
(props.cosmetics.badges ?? [])
?.filter((b) => !props.owned.badges.some((b2) => b.tag === b2.id))
.map((badge) => getBadgeByID(badge.tag, badge.id, badge))
.filter((x) => x?.refID)
.filter((x) => !x?.name || x?.name.toLowerCase().includes(filter.value.toLowerCase()))
.map((b) => [b!.id, b!]),
).values(),
],
paints:
props.cosmetics.paints
Expand Down Expand Up @@ -156,12 +156,22 @@ const assignEntitlement = () => {
condition: subOnly.value ? { all_roles: ["6076a86b09a4c63a38ebe801"] } : undefined,
};
const store = useStore();
fetch(import.meta.env.VITE_APP_API_REST + "/entitlements", {
method: "POST",
credentials: "include",
headers: {
"Content-Type": "application/json",
},
headers: (() => {
const headers: HeadersInit = {
"Content-Type": "application/json",
};
if (store.authToken) {
headers["Authorization"] = `Bearer ${store.authToken}`;
}
return headers;
})(),
body: JSON.stringify(body),
}).then(onClose);
};
Expand Down

0 comments on commit 7042b2d

Please sign in to comment.