diff --git a/src/lib/common/apiFunctions.svelte b/src/lib/common/apiFunctions.svelte index 4a5d9d5..206ac73 100644 --- a/src/lib/common/apiFunctions.svelte +++ b/src/lib/common/apiFunctions.svelte @@ -51,13 +51,13 @@ filterUsers(); } - export async function editUser(currentUsername: string, newUsername: string): Promise { + export async function editUser(currentUserId: string, newUsername: string): Promise { // variables in local storage let headscaleURL = localStorage.getItem('headscaleURL') || ''; let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || ''; // endpoint url for editing users - let endpointURL = '/api/v1/user/' + currentUsername + '/rename/' + newUsername; + let endpointURL = '/api/v1/user/' + currentUserId + '/rename/' + newUsername; await fetch(headscaleURL + endpointURL, { method: 'POST', @@ -184,13 +184,13 @@ }); } - export async function removeUser(currentUsername: string): Promise { + export async function removeUser(currentUserId: string): Promise { // variables in local storage let headscaleURL = localStorage.getItem('headscaleURL') || ''; let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || ''; // endpoint url for editing users - let endpointURL = '/api/v1/user/' + currentUsername; + let endpointURL = '/api/v1/user/' + currentUserId; await fetch(headscaleURL + endpointURL, { method: 'DELETE', @@ -329,7 +329,7 @@ return apiKeys; } - export async function getPreauthKeys(userName: string): Promise { + export async function getPreauthKeys(userId: string): Promise { // variables in local storage let headscaleURL = localStorage.getItem('headscaleURL') || ''; let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || ''; @@ -341,7 +341,7 @@ let headscalePreAuthKey = [new PreAuthKey()]; let headscalePreAuthKeyResponse: Response = new Response(); - await fetch(headscaleURL + endpointURL + '?user=' + userName, { + await fetch(headscaleURL + endpointURL + '?user=' + userId, { method: 'GET', headers: { Accept: 'application/json', @@ -367,7 +367,7 @@ return headscalePreAuthKey; } - export async function newPreAuthKey(userName: string, expiry: string, reusable: boolean, ephemeral: boolean): Promise { + export async function newPreAuthKey(userId: string, expiry: string, reusable: boolean, ephemeral: boolean): Promise { // variables in local storage let headscaleURL = localStorage.getItem('headscaleURL') || ''; let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || ''; @@ -381,7 +381,7 @@ Authorization: `Bearer ${headscaleAPIKey}` }, body: JSON.stringify({ - user: userName, + user: userId, expiration: expiry, reusable: reusable, ephemeral: ephemeral @@ -401,7 +401,7 @@ }); } - export async function removePreAuthKey(userName: string, preAuthKey: string): Promise { + export async function removePreAuthKey(userId: string, preAuthKey: string): Promise { // variables in local storage let headscaleURL = localStorage.getItem('headscaleURL') || ''; let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || ''; @@ -416,7 +416,7 @@ Authorization: `Bearer ${headscaleAPIKey}` }, body: JSON.stringify({ - user: userName, + user: userId, key: preAuthKey }) }) @@ -434,7 +434,7 @@ }); } - export async function newDevice(key: string, userName: string): Promise { + export async function newDevice(key: string, userId: string): Promise { // variables in local storage let headscaleURL = localStorage.getItem('headscaleURL') || ''; @@ -443,7 +443,7 @@ // endpoint url for editing users let endpointURL = `/api/v1/node/register`; - await fetch(headscaleURL + endpointURL + '?user=' + userName + '&key=' + key, { + await fetch(headscaleURL + endpointURL + '?user=' + userId + '&key=' + key, { method: 'POST', headers: { Accept: 'application/json', diff --git a/src/lib/users/UserCard/PreAuthKeys.svelte b/src/lib/users/UserCard/PreAuthKeys.svelte index 7c5ea4c..086ccb9 100644 --- a/src/lib/users/UserCard/PreAuthKeys.svelte +++ b/src/lib/users/UserCard/PreAuthKeys.svelte @@ -10,8 +10,8 @@ export let keyList = [new PreAuthKey]; let newPreAuthKeyShow = false; - function expirePreAuthKeyAction(userName: string, preAuthKey: string) { - removePreAuthKey(userName, preAuthKey) + function expirePreAuthKeyAction(userId: string, preAuthKey: string) { + removePreAuthKey(userId, preAuthKey) .then(() => { getPreauthKeysAction(); }) @@ -107,7 +107,7 @@ {#if new Date(key.expiration).getTime() > new Date().getTime() && (!key.used || key.reusable)} - { newPreAuthKeyShow = false; getPreauthKeysAction(); @@ -26,7 +26,7 @@ } function getPreauthKeysAction() { - getPreauthKeys(user.name) + getPreauthKeys(user.id) .then((keys) => { keyList = keys; }) diff --git a/src/lib/users/UserCard/RemoveUser.svelte b/src/lib/users/UserCard/RemoveUser.svelte index a44f2af..15968e9 100644 --- a/src/lib/users/UserCard/RemoveUser.svelte +++ b/src/lib/users/UserCard/RemoveUser.svelte @@ -8,7 +8,7 @@ let cardDeleting = false; function removeUserAction() { - removeUser(user.name) + removeUser(user.id) .then((response) => { cardDeleting = false; // refresh users after editing diff --git a/src/lib/users/UserCard/RenameUser.svelte b/src/lib/users/UserCard/RenameUser.svelte index 4972090..7728ac8 100644 --- a/src/lib/users/UserCard/RenameUser.svelte +++ b/src/lib/users/UserCard/RenameUser.svelte @@ -16,7 +16,7 @@ function renameUserAction() { if (editUserForm.reportValidity()) { - editUser(user.name, newUserName) + editUser(user.id, newUserName) .then((response) => { cardEditing = false; // refresh users after editing