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

Rename privatePath to privateToken for consistency

parent e05f4205
......@@ -5,7 +5,7 @@
import { get } from 'svelte/store'
import { state } from '../state.js'
const { privatePath } = getContext(state)
const { privateToken } = getContext(state)
// NOTE: All this socket-related code should be taken out of the view.
let socketConnectionInitialised = false
......@@ -13,10 +13,10 @@
function onShow() {
if (socketConnectionInitialised) return ''
console.log('Attempting to connect using private token', get(privatePath))
console.log('Attempting to connect using private token', get(privateToken))
// Create a web socket connection.
const privateSocket = new WebSocket(`wss://${location.hostname}/private/${get(privatePath)}`)
const privateSocket = new WebSocket(`wss://${location.hostname}/private/${get(privateToken)}`)
privateSocket.onmessage = message => {
messages = [...messages, message]
}
......
......@@ -7,10 +7,10 @@
const path = '/sign-in'
let { signedIn, privatePath, currentSection } = getContext(state)
let { signedIn, privateToken, currentSection } = getContext(state)
let passphraseField
let _privatePath = undefined
let _privateToken = undefined
// Make sure the passphrase field has focus if it’s showing.
$: if (passphraseField != undefined) {
......@@ -18,11 +18,11 @@
}
async function signInSucceeded(){
$privatePath = await _privatePath
$privateToken = await _privateToken
// Once we’ve stored the promise, unset it here so that
// it is not persisted on the view. (Otherwise, after signing out,
// it will return here and find the successful sign in.)
_privatePath = undefined
_privateToken = undefined
$signedIn = true
$currentSection = '/private'
location.hash = '/private'
......@@ -33,7 +33,7 @@
}
function handleSignIn () {
_privatePath = authenticate(passphraseField.value)
_privateToken = authenticate(passphraseField.value)
}
</script>
......@@ -44,7 +44,7 @@
<button>Sign in</button>
</form>
{#await _privatePath}
{#await _privateToken}
<p>Authenticating…</p>
<BarLoader />
{:then value}
......
......@@ -3,10 +3,10 @@
import { state } from '../state.js'
import Section from './Section.svelte'
let { signedIn, privatePath, currentSection } = getContext(state)
let { signedIn, privateToken, currentSection } = getContext(state)
async function handleSignOut () {
$privatePath = null
$privateToken = null
$signedIn = false
$currentSection = '/private'
location.hash = '/sign-in'
......
......@@ -10,10 +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 privateToken = writable(null)
const currentSection = writable(currentSectionFromHash(false))
setContext(state, { currentSection, signedIn, privatePath })
setContext(state, { currentSection, signedIn, privateToken })
window.addEventListener('hashchange', () => {
const _signedIn = 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