basic preauth keys

This commit is contained in:
Christopher Bisset 2022-07-17 12:25:13 +10:00
parent 209f1ece93
commit 9e650cd8bc
5 changed files with 11 additions and 6 deletions

View file

@ -203,6 +203,7 @@
await headscalePreAuthKeyResponse.json().then((data) => {
headscalePreAuthKey = data.preAuthKeys;
console.log(headscalePreAuthKey);
});
return headscalePreAuthKey;
}

View file

@ -28,6 +28,7 @@ export class PreAuthKey {
public expiration: string = '';
public reusable: boolean = false;
public ephemeral: boolean = false;
public used: boolean = false;
public constructor(init?: Partial<Device>) {
Object.assign(this, init);

View file

@ -7,11 +7,14 @@
export let user = new User();
let keyList = [new PreAuthKey()];
function testExpiry(keyExpiry: string): string {
if((new Date(keyExpiry)).getTime() > (new Date()).getTime()) {
return "text-success"
// If the key hasn't expired or key hasn't been used, flag as green, otherwise flag as red
function testExpiry(keyExpiry: string, keyUsed: boolean): string {
if (new Date(keyExpiry).getTime() > new Date().getTime()) {
if (!keyUsed) {
return 'text-success';
}
}
return "text-error"
return 'text-error';
}
function getPreauthKeysAction() {
@ -36,7 +39,7 @@
<td
><ul class="list-disc list-inside">
{#each keyList as key}
<li><span class="{testExpiry(key.expiration)}">{key.key} </span></li>
<li><span class="{testExpiry(key.expiration, key.used)}">{key.key} </span></li>
{/each}
</ul></td
>

View file

@ -1,6 +1,6 @@
<!-- typescript -->
<script lang="ts">
import CreateUser from '$lib/index/UserCard/CreateUser.svelte';
import CreateUser from '$lib/index/CreateUser.svelte';
import UserCard from '$lib/index/UserCard.svelte';
import { headscaleUserStore, apiTestStore } from '$lib/common/stores';
import { onMount } from 'svelte';