diff --git a/src/components/GenerateToken.vue b/src/components/GenerateToken.vue new file mode 100644 index 0000000..12b6b4a --- /dev/null +++ b/src/components/GenerateToken.vue @@ -0,0 +1,43 @@ + + + + + + > {{ api_token_store.api_token.secret }} + + + > Claims: + + + > iss: {{ api_token_store.api_token.claims.iss }} + + + > sub: {{ api_token_store.api_token.claims.sub }} + + + + + + + + > Name: + + + + + > SUBMIT + + + diff --git a/src/ts/apitoken.ts b/src/ts/apitoken.ts new file mode 100644 index 0000000..a68caff --- /dev/null +++ b/src/ts/apitoken.ts @@ -0,0 +1,30 @@ +import { reactive, ref } from 'vue' + +export const api_token_store = reactive({ + api_token: ref({ + secret: '', + claims: { + iss: '', + sub: '', + }, + }), +}) + +export function generate_api_token(key_name: string): Promise { + const get_url = new URL('http://192.168.50.91:31337/user/token/generate') + const search_params = new URLSearchParams() + search_params.append('name', key_name) + get_url.search = search_params.toString() + return fetch(get_url, { + credentials: 'include', + method: 'GET', + }) + .then((res) => { + return res.json().then((res_json) => { + console.log(res_json) + api_token_store.api_token = res_json + return res_json + }) + }) + .catch(() => {}) +} diff --git a/src/views/UserDashboard.vue b/src/views/UserDashboard.vue index 20548bc..1f8e3c2 100644 --- a/src/views/UserDashboard.vue +++ b/src/views/UserDashboard.vue @@ -12,6 +12,7 @@ import { update_info } from '@/ts/user_info' import { update_groups } from '@/ts/groups' import { get_functions } from '@/ts/functions' import { update_function_tags } from '@/ts/function_tags' +import GenerateToken from '@/components/GenerateToken.vue' import UpdateFunction from '@/components/UpdateFunction.vue' onMounted(update_info) @@ -38,6 +39,11 @@ onMounted(update_function_tags) + + + + +
> {{ api_token_store.api_token.secret }}
> Claims:
+ > iss: {{ api_token_store.api_token.claims.iss }} +
+ > sub: {{ api_token_store.api_token.claims.sub }} +