From 91b4bfa2d616f96170d7214b81f596d95c4de0b6 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Wed, 11 Sep 2024 16:29:27 +0100 Subject: Fetch current voucher token from store when fetched --- thallium-frontend/src/api/vouchers.ts | 13 ++++++++++--- 1 file 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 => { +export const getCurrentVoucher = async (): Promise => { + 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; }; -- cgit v1.2.3