Skip to content

Commit 216a49e

Browse files
authored
fix: headscale 25 uses user's "name" instead of "id" to get/create/expire pre-auth keys (#192)
1 parent 21075b9 commit 216a49e

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/lib/common/apiFunctions.svelte

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@
329329
return apiKeys;
330330
}
331331
332-
export async function getPreauthKeys(userId: string): Promise<PreAuthKey[]> {
332+
export async function getPreauthKeys(userName: 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=' + userId, {
344+
await fetch(headscaleURL + endpointURL + '?user=' + userName, {
345345
method: 'GET',
346346
headers: {
347347
Accept: 'application/json',
@@ -367,7 +367,7 @@
367367
return headscalePreAuthKey;
368368
}
369369
370-
export async function newPreAuthKey(userId: string, expiry: string, reusable: boolean, ephemeral: boolean): Promise<any> {
370+
export async function newPreAuthKey(userName: 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: userId,
384+
user: userName,
385385
expiration: expiry,
386386
reusable: reusable,
387387
ephemeral: ephemeral
@@ -401,7 +401,7 @@
401401
});
402402
}
403403
404-
export async function removePreAuthKey(userId: string, preAuthKey: string): Promise<any> {
404+
export async function removePreAuthKey(userName: 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: userId,
419+
user: userName,
420420
key: preAuthKey
421421
})
422422
})

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(userId: string, preAuthKey: string) {
14-
removePreAuthKey(userId, preAuthKey)
13+
function expirePreAuthKeyAction(userName: string, preAuthKey: string) {
14+
removePreAuthKey(userName, 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.id, key.key)}}
110+
<button class="mr-2" on:click={() => {expirePreAuthKeyAction(user.name, 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.id, formattedDate, reusable, ephemeral)
18+
newPreAuthKey(user.name, formattedDate, reusable, ephemeral)
1919
.then(() => {
2020
newPreAuthKeyShow = false;
2121
getPreauthKeysAction();
@@ -26,7 +26,7 @@
2626
}
2727
2828
function getPreauthKeysAction() {
29-
getPreauthKeys(user.id)
29+
getPreauthKeys(user.name)
3030
.then((keys) => {
3131
keyList = keys;
3232
})

0 commit comments

Comments
 (0)