Skip to content

Commit 3e56511

Browse files
authored
Make headscale-ui compatible with headscale v0.24 - *BREAKING* (#185)
1 parent 7a1725d commit 3e56511

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

src/lib/common/apiFunctions.svelte

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@
5151
filterUsers();
5252
}
5353
54-
export async function editUser(currentUsername: string, newUsername: string): Promise<any> {
54+
export async function editUser(currentUserId: string, newUsername: string): Promise<any> {
5555
// variables in local storage
5656
let headscaleURL = localStorage.getItem('headscaleURL') || '';
5757
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
5858
5959
// endpoint url for editing users
60-
let endpointURL = '/api/v1/user/' + currentUsername + '/rename/' + newUsername;
60+
let endpointURL = '/api/v1/user/' + currentUserId + '/rename/' + newUsername;
6161
6262
await fetch(headscaleURL + endpointURL, {
6363
method: 'POST',
@@ -184,13 +184,13 @@
184184
});
185185
}
186186
187-
export async function removeUser(currentUsername: string): Promise<any> {
187+
export async function removeUser(currentUserId: string): Promise<any> {
188188
// variables in local storage
189189
let headscaleURL = localStorage.getItem('headscaleURL') || '';
190190
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
191191
192192
// endpoint url for editing users
193-
let endpointURL = '/api/v1/user/' + currentUsername;
193+
let endpointURL = '/api/v1/user/' + currentUserId;
194194
195195
await fetch(headscaleURL + endpointURL, {
196196
method: 'DELETE',
@@ -329,7 +329,7 @@
329329
return apiKeys;
330330
}
331331
332-
export async function getPreauthKeys(userName: string): Promise<PreAuthKey[]> {
332+
export async function getPreauthKeys(userId: string): Promise<PreAuthKey[]> {
333333
// variables in local storage
334334
let headscaleURL = localStorage.getItem('headscaleURL') || '';
335335
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
@@ -341,7 +341,7 @@
341341
let headscalePreAuthKey = [new PreAuthKey()];
342342
let headscalePreAuthKeyResponse: Response = new Response();
343343
344-
await fetch(headscaleURL + endpointURL + '?user=' + userName, {
344+
await fetch(headscaleURL + endpointURL + '?user=' + userId, {
345345
method: 'GET',
346346
headers: {
347347
Accept: 'application/json',
@@ -367,7 +367,7 @@
367367
return headscalePreAuthKey;
368368
}
369369
370-
export async function newPreAuthKey(userName: string, expiry: string, reusable: boolean, ephemeral: boolean): Promise<any> {
370+
export async function newPreAuthKey(userId: string, expiry: string, reusable: boolean, ephemeral: boolean): Promise<any> {
371371
// variables in local storage
372372
let headscaleURL = localStorage.getItem('headscaleURL') || '';
373373
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
@@ -381,7 +381,7 @@
381381
Authorization: `Bearer ${headscaleAPIKey}`
382382
},
383383
body: JSON.stringify({
384-
user: userName,
384+
user: userId,
385385
expiration: expiry,
386386
reusable: reusable,
387387
ephemeral: ephemeral
@@ -401,7 +401,7 @@
401401
});
402402
}
403403
404-
export async function removePreAuthKey(userName: string, preAuthKey: string): Promise<any> {
404+
export async function removePreAuthKey(userId: string, preAuthKey: string): Promise<any> {
405405
// variables in local storage
406406
let headscaleURL = localStorage.getItem('headscaleURL') || '';
407407
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
@@ -416,7 +416,7 @@
416416
Authorization: `Bearer ${headscaleAPIKey}`
417417
},
418418
body: JSON.stringify({
419-
user: userName,
419+
user: userId,
420420
key: preAuthKey
421421
})
422422
})
@@ -434,7 +434,7 @@
434434
});
435435
}
436436
437-
export async function newDevice(key: string, userName: string): Promise<any> {
437+
export async function newDevice(key: string, userId: string): Promise<any> {
438438
439439
// variables in local storage
440440
let headscaleURL = localStorage.getItem('headscaleURL') || '';
@@ -443,7 +443,7 @@
443443
// endpoint url for editing users
444444
let endpointURL = `/api/v1/node/register`;
445445
446-
await fetch(headscaleURL + endpointURL + '?user=' + userName + '&key=' + key, {
446+
await fetch(headscaleURL + endpointURL + '?user=' + userId + '&key=' + key, {
447447
method: 'POST',
448448
headers: {
449449
Accept: 'application/json',

src/lib/users/UserCard/PreAuthKeys.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
export let keyList = [new PreAuthKey];
1111
let newPreAuthKeyShow = false;
1212
13-
function expirePreAuthKeyAction(userName: string, preAuthKey: string) {
14-
removePreAuthKey(userName, preAuthKey)
13+
function expirePreAuthKeyAction(userId: string, preAuthKey: string) {
14+
removePreAuthKey(userId, preAuthKey)
1515
.then(() => {
1616
getPreauthKeysAction();
1717
})
@@ -107,7 +107,7 @@
107107
<!-- Allow ability to expire if not expired -->
108108
{#if new Date(key.expiration).getTime() > new Date().getTime() && (!key.used || key.reusable)}
109109
<!-- trash symbol -->
110-
<button class="mr-2" on:click={() => {expirePreAuthKeyAction(user.name, key.key)}}
110+
<button class="mr-2" on:click={() => {expirePreAuthKeyAction(user.id, key.key)}}
111111
><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">
112112
<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" />
113113
</svg></button

src/lib/users/UserCard/PreAuthKeys/NewPreAuthKey.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
function NewPreAuthKeyAction() {
1717
let formattedDate = new Date(expiry).toISOString();
18-
newPreAuthKey(user.name, formattedDate, reusable, ephemeral)
18+
newPreAuthKey(user.id, formattedDate, reusable, ephemeral)
1919
.then(() => {
2020
newPreAuthKeyShow = false;
2121
getPreauthKeysAction();
@@ -26,7 +26,7 @@
2626
}
2727
2828
function getPreauthKeysAction() {
29-
getPreauthKeys(user.name)
29+
getPreauthKeys(user.id)
3030
.then((keys) => {
3131
keyList = keys;
3232
})

src/lib/users/UserCard/RemoveUser.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
let cardDeleting = false;
99
1010
function removeUserAction() {
11-
removeUser(user.name)
11+
removeUser(user.id)
1212
.then((response) => {
1313
cardDeleting = false;
1414
// refresh users after editing

src/lib/users/UserCard/RenameUser.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
function renameUserAction() {
1818
if (editUserForm.reportValidity()) {
19-
editUser(user.name, newUserName)
19+
editUser(user.id, newUserName)
2020
.then((response) => {
2121
cardEditing = false;
2222
// refresh users after editing

0 commit comments

Comments
 (0)