From 3be0755074d1366830d3700cc651168b6df7fba4 Mon Sep 17 00:00:00 2001 From: Brian DeRocher Date: Sat, 25 Oct 2025 10:51:56 -0400 Subject: [PATCH] Get sticker data from the API backend. Store the JWT access token and use it later to get the sticker. Add missing url property of stickers. --- src/stores/sessionStore.ts | 1 + src/stores/stickersStore.ts | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/stores/sessionStore.ts b/src/stores/sessionStore.ts index 87a8821..2c2245e 100644 --- a/src/stores/sessionStore.ts +++ b/src/stores/sessionStore.ts @@ -31,6 +31,7 @@ export const useSessionStore = defineStore('session', { }, ); const json = await response.json(); + localStorage.setItem('access_token', json.access_token); const payload = parseJwt(json.access_token); // Fetch the user record. const userStore= useUserStore(); diff --git a/src/stores/stickersStore.ts b/src/stores/stickersStore.ts index d0d88c2..15a51cf 100644 --- a/src/stores/stickersStore.ts +++ b/src/stores/stickersStore.ts @@ -7,14 +7,15 @@ import { useUserStore } from '@/stores/userStore' export interface Sticker { color: string, createdBy: string | null, + id: string, layout: string, - orgs: string[], message1: string | null, message2: string | null, message3: string | null, message4: string | null, owner: string | null, - id: string, + orgs: string[], + url: string | null, } export const activist: Sticker = { @@ -65,8 +66,14 @@ export const useStickersStore = defineStore('stickers', { return; } // TODO: Check if we have it already and if it's stale. + const accessToken = localStorage.getItem('access_token'); const response = await fetch( - `/api/sticker/${id}`, + `/api-2/sticker/${id}`, + { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }, ); const json = await response.json(); this.stickers.push(json); @@ -77,9 +84,12 @@ export const useStickersStore = defineStore('stickers', { return; } const response = await fetch( - `/api/sticker/${id}`, + `/api-2/sticker/${id}`, { body: JSON.stringify(sticker), + headers: { + 'Content-Type': 'application/json', + }, method: 'PUT', }, ); @@ -88,7 +98,7 @@ export const useStickersStore = defineStore('stickers', { // this.sticker = json; }, setOwner(sticker: Sticker, user: User) { - sticker.owner = user.username; + sticker.owner = user.user_id; this.put(sticker.id); const userStore= useUserStore(); userStore.addSticker(user.username, sticker.id);