improve generation of session id
This commit is contained in:
parent
2ff0811346
commit
f345d7e8bc
1 changed files with 7 additions and 4 deletions
|
@ -66,20 +66,23 @@ function poll() {
|
||||||
function createSid(): string {
|
function createSid(): string {
|
||||||
const arr = new Uint32Array(2)
|
const arr = new Uint32Array(2)
|
||||||
crypto.getRandomValues(arr)
|
crypto.getRandomValues(arr)
|
||||||
//return arr.map((x) => x.toString(36)).join('')
|
const result: string[] = []
|
||||||
return arr[0].toString(36) + arr[1].toString(36)
|
arr.forEach((x) => result.push(x.toString(36)))
|
||||||
|
return result.join('')
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSid(): string {
|
function getSid(): string {
|
||||||
let sid = localStorage.getItem('api.sessionid')
|
const sid_key = 'api.sessionid'
|
||||||
|
let sid = localStorage.getItem(sid_key)
|
||||||
if (!sid) {
|
if (!sid) {
|
||||||
sid = createSid()
|
sid = createSid()
|
||||||
localStorage.setItem('api.sessionid', sid)
|
localStorage.setItem(sid_key, sid)
|
||||||
}
|
}
|
||||||
return sid
|
return sid
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("sid: ", getSid())
|
console.log("sid: ", getSid())
|
||||||
|
//localStorage.setItem('api.sessionid', '')
|
||||||
// TODO: clear sid - when?
|
// TODO: clear sid - when?
|
||||||
|
|
||||||
async function dopoll(app: typeof appdata) {
|
async function dopoll(app: typeof appdata) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue