Commit a6df46c6 authored by Aral Balkan's avatar Aral Balkan
Browse files

Now redirecting to private section on successful sign in

parent c7e04d6b
......@@ -7,20 +7,29 @@
const path = '/sign-in'
let { currentSection } = getContext(state)
let { signedIn, privatePath, currentSection } = getContext(state)
let passphraseField
let secretPath = undefined
let _privatePath = undefined
// Make sure the passphrase field has focus if it’s showing.
$: if (passphraseField != undefined) {
passphraseField.focus()
}
function handleSignIn () {
secretPath = authenticate(passphraseField.value)
function signInSucceeded(){
$privatePath = _privatePath
$currentSection = '/private'
$signedIn = true
// Returning an empty string as we’re called
// from within the template’s await.
return ''
}
function handleSignIn () {
_privatePath = authenticate(passphraseField.value)
}
</script>
<Section {path} title='Sign in'>
......@@ -30,15 +39,15 @@
<button>Sign in</button>
</form>
{#await secretPath}
{#await _privatePath}
<p>Authenticating…</p>
<BarLoader />
{:then value}
{#if value !== undefined}
{#if value === null}
<p>Sign in failed. Please try again.</p>
<p><strong>Sign in failed.</strong> Please try again.</p>
{:else}
<p>Secret path is {value}</p>
{ signInSucceeded() }
{/if}
{/if}
{:catch error}
......@@ -46,5 +55,3 @@
{/await}
</Section>
......@@ -10,9 +10,10 @@ export const state = {}
// Set initial application state, including the current section based on the hash.
export function initialise () {
const signedIn = writable(false)
const privatePath = writable(null)
const currentSection = writable(currentSectionFromHash(false))
setContext(state, { currentSection, signedIn })
setContext(state, { currentSection, signedIn, privatePath })
window.addEventListener('hashchange', () => {
currentSection.update(value => value = currentSectionFromHash(get(signedIn)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment