Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/lib/common/apiFunctions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
filterUsers();
}

export async function editUser(currentUsername: string, newUsername: string): Promise<any> {
export async function editUser(currentUserId: string, newUsername: string): Promise<any> {
// 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',
Expand Down Expand Up @@ -184,13 +184,13 @@
});
}

export async function removeUser(currentUsername: string): Promise<any> {
export async function removeUser(currentUserId: string): Promise<any> {
// 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',
Expand Down Expand Up @@ -329,7 +329,7 @@
return apiKeys;
}

export async function getPreauthKeys(userName: string): Promise<PreAuthKey[]> {
export async function getPreauthKeys(userId: string): Promise<PreAuthKey[]> {
// variables in local storage
let headscaleURL = localStorage.getItem('headscaleURL') || '';
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
Expand All @@ -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',
Expand All @@ -367,7 +367,7 @@
return headscalePreAuthKey;
}

export async function newPreAuthKey(userName: string, expiry: string, reusable: boolean, ephemeral: boolean): Promise<any> {
export async function newPreAuthKey(userId: string, expiry: string, reusable: boolean, ephemeral: boolean): Promise<any> {
// variables in local storage
let headscaleURL = localStorage.getItem('headscaleURL') || '';
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
Expand All @@ -381,7 +381,7 @@
Authorization: `Bearer ${headscaleAPIKey}`
},
body: JSON.stringify({
user: userName,
user: userId,
expiration: expiry,
reusable: reusable,
ephemeral: ephemeral
Expand All @@ -401,7 +401,7 @@
});
}

export async function removePreAuthKey(userName: string, preAuthKey: string): Promise<any> {
export async function removePreAuthKey(userId: string, preAuthKey: string): Promise<any> {
// variables in local storage
let headscaleURL = localStorage.getItem('headscaleURL') || '';
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
Expand All @@ -416,7 +416,7 @@
Authorization: `Bearer ${headscaleAPIKey}`
},
body: JSON.stringify({
user: userName,
user: userId,
key: preAuthKey
})
})
Expand All @@ -434,7 +434,7 @@
});
}

export async function newDevice(key: string, userName: string): Promise<any> {
export async function newDevice(key: string, userId: string): Promise<any> {

// variables in local storage
let headscaleURL = localStorage.getItem('headscaleURL') || '';
Expand All @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions src/lib/users/UserCard/PreAuthKeys.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
Expand Down Expand Up @@ -107,7 +107,7 @@
<!-- Allow ability to expire if not expired -->
{#if new Date(key.expiration).getTime() > new Date().getTime() && (!key.used || key.reusable)}
<!-- trash symbol -->
<button class="mr-2" on:click={() => {expirePreAuthKeyAction(user.name, key.key)}}
<button class="mr-2" on:click={() => {expirePreAuthKeyAction(user.id, key.key)}}
><svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 inline flex-shrink-0" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
</svg></button
Expand Down
4 changes: 2 additions & 2 deletions src/lib/users/UserCard/PreAuthKeys/NewPreAuthKey.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

function NewPreAuthKeyAction() {
let formattedDate = new Date(expiry).toISOString();
newPreAuthKey(user.name, formattedDate, reusable, ephemeral)
newPreAuthKey(user.id, formattedDate, reusable, ephemeral)
.then(() => {
newPreAuthKeyShow = false;
getPreauthKeysAction();
Expand All @@ -26,7 +26,7 @@
}

function getPreauthKeysAction() {
getPreauthKeys(user.name)
getPreauthKeys(user.id)
.then((keys) => {
keyList = keys;
})
Expand Down
2 changes: 1 addition & 1 deletion src/lib/users/UserCard/RemoveUser.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let cardDeleting = false;

function removeUserAction() {
removeUser(user.name)
removeUser(user.id)
.then((response) => {
cardDeleting = false;
// refresh users after editing
Expand Down
2 changes: 1 addition & 1 deletion src/lib/users/UserCard/RenameUser.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down