Commit d55a605a authored by Jakob Moser's avatar Jakob Moser
Browse files

Merge branch 'add-uuid-to-state' into 'master'

Add uuid to state

Closes #39

See merge request !9
parents 4b4a9cad 795246a9
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -45,3 +45,12 @@ export function getHandInToken(state) {
     */
    return btoa(state.toString())
}

/**
 * Generate a random session uuid, whose sole purpose it is
 * to distinguish a hand-in token from this session from a hand-in
 * token from any other session.
 */
export function generateSessionUuid() {
    return crypto.randomUUID()
}
+15 −0
Original line number Diff line number Diff line
/** Read and modify the current state of the application. Allows saving to local storage. */

import { generateSessionUuid } from "./snakeoil.mjs"

export class State {

    /**
@@ -11,6 +13,19 @@ export class State {
        this.realm = realm
    }

    /**
     * Return a uuid for this test session
     */
    get sessionUuid() {
        let uuid = localStorage.getItem(`${this.realm}.sessionUuid`)
        if(uuid === null) {
            uuid = generateSessionUuid()
            localStorage.setItem(`${this.realm}.sessionUuid`, uuid)
        }

        return uuid
    }

    /**
     * Return if this is the first time the application was started
     */