mirror of
https://github.com/gurucomputing/headscale-ui.git
synced 2026-01-23 02:34:43 +00:00
redirect to page if default creds are set
This commit is contained in:
parent
7847e11830
commit
7b34e1c3b7
7 changed files with 37 additions and 5 deletions
8
package-lock.json
generated
8
package-lock.json
generated
|
|
@ -16,6 +16,7 @@
|
|||
"@tailwindcss/postcss": "^4.0.15",
|
||||
"@tailwindcss/typography": "^0.5.16",
|
||||
"daisyui": "^5.0.9",
|
||||
"pocketbase": "^0.26.2",
|
||||
"prettier": "^3.3.2",
|
||||
"prettier-plugin-svelte": "^3.2.6",
|
||||
"prettier-plugin-tailwindcss": "^0.6.11",
|
||||
|
|
@ -1936,6 +1937,13 @@
|
|||
"url": "https://github.com/sponsors/jonschlinkert"
|
||||
}
|
||||
},
|
||||
"node_modules/pocketbase": {
|
||||
"version": "0.26.2",
|
||||
"resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.26.2.tgz",
|
||||
"integrity": "sha512-WA8EOBc3QnSJh8rJ3iYoi9DmmPOMFIgVfAmIGux7wwruUEIzXgvrO4u0W2htfQjGIcyezJkdZOy5Xmh7SxAftw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/postcss": {
|
||||
"version": "8.5.6",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz",
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
"@tailwindcss/postcss": "^4.0.15",
|
||||
"@tailwindcss/typography": "^0.5.16",
|
||||
"daisyui": "^5.0.9",
|
||||
"pocketbase": "^0.26.2",
|
||||
"prettier": "^3.3.2",
|
||||
"prettier-plugin-svelte": "^3.2.6",
|
||||
"prettier-plugin-tailwindcss": "^0.6.11",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<script module lang="ts">
|
||||
import { SvelteMap } from 'svelte/reactivity';
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
export class PersistentAppSettingsObject {
|
||||
daisyUITheme = 'winter'; // for setting the UI theme. See https://daisyui.com/docs/themes/
|
||||
|
|
@ -19,6 +20,7 @@
|
|||
toastAlerts = new SvelteMap<string, toastAlert>(); // for adding or removing alerts
|
||||
apiTested = true; // used to hide the app if the api tests are failing
|
||||
apiKeyList: APIKey[] = []; //list of apikeys retrieved from headscale API
|
||||
pb: PocketBase = new PocketBase(); //authentication middleware interface
|
||||
users: user[] = []; //list of users retrieved from headscale API
|
||||
apiKeyExpiration?: number = undefined; // number of days left until the key in use expires
|
||||
|
||||
|
|
|
|||
19
src/lib/components/layout/auth-functions.svelte
Normal file
19
src/lib/components/layout/auth-functions.svelte
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<script module lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import{ resolve } from '$app/paths';
|
||||
import { appSettings } from '../common/state.svelte';
|
||||
|
||||
export async function checkAuth() {
|
||||
|
||||
// attempt to authenticate with default credentials and redirect to first registration screen
|
||||
try {
|
||||
let authData = await appSettings.pb.collection("_superusers").authWithPassword('superadmin@breakglass.local', 'firsttimepasswordchangeme');
|
||||
if (authData) {
|
||||
appSettings.pb.authStore.clear();
|
||||
goto(resolve(`/firstregistration.html`));
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('not authenticated');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
@ -4,10 +4,10 @@
|
|||
import Navbar from '$lib/components/layout/navbar.svelte';
|
||||
import Sidebar from '$lib/components/layout/sidebar.svelte';
|
||||
import Toast from '$lib/components/layout/toast.svelte';
|
||||
import { getAPIKeys } from '$lib/components/settings/server-settings-functions.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import { fade } from 'svelte/transition';
|
||||
import '../app.css';
|
||||
import { checkAuth } from '$lib/components/layout/auth-functions.svelte';
|
||||
let { children } = $props();
|
||||
|
||||
onMount(async () => {
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
localStorage.setItem('persistentAppSettings', JSON.stringify(persistentAppSettings));
|
||||
});
|
||||
|
||||
|
||||
// populate any settings being passed through by url params
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
let headscaleApiKeyParam = urlParams.get('apikey');
|
||||
|
|
@ -33,8 +34,8 @@
|
|||
persistentAppSettings.headscaleURL = headscaleUrlParam;
|
||||
}
|
||||
|
||||
// perform an initial API test
|
||||
getAPIKeys();
|
||||
// do an initial authentication check
|
||||
checkAuth();
|
||||
|
||||
// delay load until page is hydrated
|
||||
appSettings.appLoaded = true;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { base } from '$app/paths';
|
||||
import { resolve } from '$app/paths';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
onMount(async () => {
|
||||
goto(`${base}/users.html`);
|
||||
goto(resolve(`/users.html`));
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
1
src/routes/firstregistration.html/+page.svelte
Normal file
1
src/routes/firstregistration.html/+page.svelte
Normal file
|
|
@ -0,0 +1 @@
|
|||
firstregistration
|
||||
Loading…
Add table
Add a link
Reference in a new issue