70 lines
2.1 KiB
Svelte
70 lines
2.1 KiB
Svelte
<script>
|
|
import { invoke } from '@tauri-apps/api/tauri';
|
|
import { onMount } from 'svelte';
|
|
|
|
import { appState } from '../lib/state.js';
|
|
import { navigate } from '../lib/routing.js';
|
|
import { getRootCause } from '../lib/errors.js';
|
|
import ErrorAlert from '../ui/ErrorAlert.svelte';
|
|
import Link from '../ui/Link.svelte';
|
|
|
|
|
|
let errorMsg = null;
|
|
let alert;
|
|
let passphrase = '';
|
|
let loadTime = 0;
|
|
async function unlock() {
|
|
// The hotkey for navigating here from homepage is Enter, which also
|
|
// happens to trigger the form submit event
|
|
if (Date.now() - loadTime < 10) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
let r = await invoke('unlock', {passphrase});
|
|
$appState.credentialStatus = 'unlocked';
|
|
if ($appState.currentRequest) {
|
|
navigate('Approve');
|
|
}
|
|
else {
|
|
navigate('Home');
|
|
}
|
|
}
|
|
catch (e) {
|
|
window.error = e;
|
|
if (e.code === 'GetSession') {
|
|
let root = getRootCause(e);
|
|
errorMsg = `Error response from AWS (${root.code}): ${root.msg}`;
|
|
}
|
|
else {
|
|
errorMsg = e.msg;
|
|
}
|
|
|
|
if (alert) {
|
|
alert.shake();
|
|
}
|
|
}
|
|
}
|
|
|
|
onMount(() => {
|
|
loadTime = Date.now();
|
|
})
|
|
</script>
|
|
|
|
|
|
<form action="#" on:submit|preventDefault="{unlock}" class="form-control space-y-4 max-w-sm m-auto p-4 h-screen justify-center">
|
|
<h2 class="font-bold text-2xl text-center">Enter your passphrase</h2>
|
|
|
|
{#if errorMsg}
|
|
<ErrorAlert bind:this="{alert}">{errorMsg}</ErrorAlert>
|
|
{/if}
|
|
|
|
<!-- svelte-ignore a11y-autofocus -->
|
|
<input autofocus name="password" type="password" placeholder="correct horse battery staple" bind:value="{passphrase}" class="input input-bordered" />
|
|
|
|
<input type="submit" class="btn btn-primary" />
|
|
<Link target="Home" hotkey="Escape">
|
|
<button class="btn btn-outline btn-sm w-full">Cancel</button>
|
|
</Link>
|
|
</form>
|