1
0
Fork 0

Get sticker data from the API backend.
All checks were successful
/ test (push) Successful in 4m47s

Store the JWT access token and use it later to get the sticker.

Add missing url property of stickers.
This commit is contained in:
Brian D 2025-10-25 10:51:56 -04:00
parent 929f22abeb
commit 3be0755074
2 changed files with 16 additions and 5 deletions

View file

@ -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();

View file

@ -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);