diff options
author | 2024-09-11 16:29:27 +0100 | |
---|---|---|
committer | 2024-09-11 16:29:27 +0100 | |
commit | 91b4bfa2d616f96170d7214b81f596d95c4de0b6 (patch) | |
tree | 29edd85b563ddbfb0fbb1ad62306f0660573e75f /thallium-frontend | |
parent | Add component to display voucher metadata at store page (diff) |
Fetch current voucher token from store when fetched
Diffstat (limited to 'thallium-frontend')
-rw-r--r-- | thallium-frontend/src/api/vouchers.ts | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/thallium-frontend/src/api/vouchers.ts b/thallium-frontend/src/api/vouchers.ts index 9282150..7042b2d 100644 --- a/thallium-frontend/src/api/vouchers.ts +++ b/thallium-frontend/src/api/vouchers.ts @@ -1,4 +1,5 @@ -import { get } from "./client"; +import { APIMissingTokenError, get } from "./client"; +import store from "../store"; export interface Voucher { id: string; @@ -14,10 +15,16 @@ export interface VoucherClaim { jwt: string; } -export const getCurrentVoucher = async (voucherJWT: string): Promise<Voucher> => { +export const getCurrentVoucher = async (): Promise<Voucher> => { + const { voucherToken } = store.getState().authorization; + + if (!voucherToken) { + throw new APIMissingTokenError(); + } + return await get("/vouchers/me", { headers: { - Authorization: `Bearer ${voucherJWT}`, + Authorization: `Bearer ${voucherToken}`, }, }) as unknown as Voucher; }; |