Compare commits
8 Commits
@flascheng
...
main
Author | SHA1 | Date |
---|---|---|
|
b7735e2924 | |
|
d35cc8e8d1 | |
|
d34898e1e9 | |
|
93669d66dc | |
|
ec5458bf7e | |
|
efc7c49a0b | |
|
b1e4879881 | |
|
48972f84e1 |
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"version": "1.1.0",
|
"version": "1.0.0",
|
||||||
"name": "@flaschengeist/api",
|
"name": "@flaschengeist/api",
|
||||||
"author": "Tim Gröger <flaschengeist@wu5.de>",
|
"author": "Tim Gröger <flaschengeist@wu5.de>",
|
||||||
"homepage": "https://flaschengeist.dev/Flaschengeist",
|
"homepage": "https://flaschengeist.dev/Flaschengeist",
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
import { defineStore } from 'pinia';
|
|
||||||
import { api } from '../internal';
|
|
||||||
import { isAxiosError, useMainStore } from '.';
|
|
||||||
|
|
||||||
export const useApiKeyStore = defineStore({
|
|
||||||
id: 'apiKeys',
|
|
||||||
|
|
||||||
state: () => ({
|
|
||||||
apiKeys: [] as FG.ApiKey[],
|
|
||||||
}),
|
|
||||||
|
|
||||||
getters: {},
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
async getApiKeys(): Promise<FG.ApiKey[]> {
|
|
||||||
try {
|
|
||||||
const mainStore = useMainStore();
|
|
||||||
const { data } = await api.get<FG.ApiKey[]>(
|
|
||||||
`/users/${mainStore.currentUser.userid}/api_keys`
|
|
||||||
);
|
|
||||||
|
|
||||||
this.apiKeys = data;
|
|
||||||
|
|
||||||
return data;
|
|
||||||
} catch (error) {
|
|
||||||
return [] as FG.ApiKey[];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async deleteApiKey(id: number): Promise<boolean> {
|
|
||||||
const mainStore = useMainStore();
|
|
||||||
|
|
||||||
try {
|
|
||||||
await api.delete(`/users/${mainStore.currentUser.userid}/api_keys/${id}`);
|
|
||||||
this.apiKeys = this.apiKeys.filter((apiKey: FG.ApiKey) => apiKey.id !== id);
|
|
||||||
return true;
|
|
||||||
} catch (error) {
|
|
||||||
// Ignore 401, as this means we are already logged out, throw all other
|
|
||||||
if (!isAxiosError(error, 401)) throw error;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
|
|
||||||
async createApiKey(apiKey: FG.ApiKey): Promise<FG.ApiKey> {
|
|
||||||
const mainStore = useMainStore();
|
|
||||||
|
|
||||||
try {
|
|
||||||
const { data } = await api.post<FG.ApiKey>(
|
|
||||||
`/users/${mainStore.currentUser.userid}/api_keys`,
|
|
||||||
apiKey
|
|
||||||
);
|
|
||||||
|
|
||||||
this.apiKeys.push(data);
|
|
||||||
|
|
||||||
return data;
|
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
|
@ -21,4 +21,3 @@ export function isAxiosError(error: unknown, status?: number) {
|
||||||
export * from './main';
|
export * from './main';
|
||||||
export * from './session';
|
export * from './session';
|
||||||
export * from './user';
|
export * from './user';
|
||||||
export * from './apiKeys';
|
|
||||||
|
|
Loading…
Reference in New Issue