Store the JWT access token and use it later to get the sticker. Add missing url property of stickers.
This commit is contained in:
parent
929f22abeb
commit
3be0755074
2 changed files with 16 additions and 5 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue