Skip to content

Commit a4e76e4

Browse files
committed
Ensure api key is reactive
1 parent dec89a2 commit a4e76e4

File tree

7 files changed

+35
-19
lines changed

7 files changed

+35
-19
lines changed

composables/useAppRefKey.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
export default function (): string {
2-
const route = useRoute();
3-
4-
if (typeof route.params.urlpath === 'string') {
5-
return route.params.urlpath;
6-
}
7-
8-
return '';
1+
export default function (): Ref<string> {
2+
return useState('app_api_key');
93
}

middleware/setAppRefKey.global.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default defineNuxtRouteMiddleware((to, _from) => {
2+
let updated;
3+
4+
if (['/', '/dashboard', '/docs', '/login'].includes(to.path)) {
5+
return;
6+
}
7+
8+
if (typeof to.params.urlpath === 'string') {
9+
updated = to.params.urlpath;
10+
} else{
11+
updated = '';
12+
}
13+
14+
useAppRefKey().value = updated;
15+
});

pages/dashboard/app/[url-path]/settings.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
form.setValues({
2323
description: app.target?.description,
2424
title: app.target?.title,
25-
apiKey,
25+
apiKey: apiKey.value,
2626
});
2727
2828
const querySecretKey = useRoute().query?.secret_key;
@@ -44,13 +44,13 @@
4444
await app.refresh();
4545
4646
app.target = app.list.filter(
47-
(proj) => proj.app_keys[0]?.api_key === apiKey
47+
(proj) => proj.app_keys[0]?.api_key === apiKey.value
4848
)[0];
4949
5050
form.setValues({
5151
description: app.target?.description,
5252
title: app.target?.title,
53-
apiKey,
53+
apiKey: apiKey.value,
5454
});
5555
},
5656
}

stores/useApp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default defineStore('apps', () => {
7777
body: {
7878
description: payload.description,
7979
title: payload.title,
80-
apiKey: useAppRefKey(),
80+
apiKey: useAppRefKey().value,
8181
},
8282
async onResponse({ response }) {
8383
if (response.status === 200) {

stores/useAppKey.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default defineStore('appKeys', (): AppKeyStore => {
1818
await $fetch(`/apps/${id}/generate-secret-key`, {
1919
method: 'POST',
2020
body: {
21-
appKey: useAppRefKey(),
21+
appKey: useAppRefKey().value,
2222
},
2323
onResponse({ response }) {
2424
if (response.status === 200) {

stores/useModel.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ export default defineStore('models', () => {
3232
}
3333
);
3434

35-
const list = computed(() => data.value || []);
35+
const list = computed(() => {
36+
if (pending.value) {
37+
return [];
38+
}
39+
40+
return data.value || [];
41+
});
42+
3643
const isDisabled = computed(() => list.value.length === 10 || pending.value);
3744

3845
const setTarget = (md: NormalizedModel) => {
@@ -47,7 +54,7 @@ export default defineStore('models', () => {
4754
await $fetch('/models', {
4855
method: 'POST',
4956
body: {
50-
apiKey,
57+
apiKey: apiKey.value,
5158
name: body.name,
5259
schema: body.schema,
5360
},
@@ -72,7 +79,7 @@ export default defineStore('models', () => {
7279
const del = async (id: string): Promise<void> => {
7380
await $fetch(`/models/${id}`, {
7481
method: 'DELETE',
75-
query: { apiKey },
82+
query: { apiKey: apiKey.value },
7683
async onResponse({ response }) {
7784
if (response.status === 200) {
7885
toast.success('Deleted the model!');
@@ -89,7 +96,7 @@ export default defineStore('models', () => {
8996
name?: string;
9097
schema: Schema;
9198
} = {
92-
apiKey,
99+
apiKey: apiKey.value,
93100
schema: body.schema,
94101
};
95102

stores/useModelData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default defineStore('model-data', () => {
5151
const bulkDelete = async (ids: string): Promise<void> => {
5252
await $fetch(`/models/${modelId.value}/model-data`, {
5353
method: 'DELETE',
54-
query: { ids, apiKey },
54+
query: { ids, apiKey: apiKey.value },
5555
async onResponse({ response }) {
5656
if (response.status === 200) {
5757
toast.success('Deleted the model data!');
@@ -66,7 +66,7 @@ export default defineStore('model-data', () => {
6666
await $fetch(`/models/${modelId.value}/model-data`, {
6767
method: 'POST',
6868
body: {
69-
apiKey,
69+
apiKey: apiKey.value,
7070
increase: body.increase,
7171
schema: body.schema,
7272
},

0 commit comments

Comments
 (0)