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 {
|
||||
const arr = new Uint32Array(2)
|
||||
crypto.getRandomValues(arr)
|
||||
//return arr.map((x) => x.toString(36)).join('')
|
||||
return arr[0].toString(36) + arr[1].toString(36)
|
||||
const result: string[] = []
|
||||
arr.forEach((x) => result.push(x.toString(36)))
|
||||
return result.join('')
|
||||
}
|
||||
|
||||
function getSid(): string {
|
||||
let sid = localStorage.getItem('api.sessionid')
|
||||
const sid_key = 'api.sessionid'
|
||||
let sid = localStorage.getItem(sid_key)
|
||||
if (!sid) {
|
||||
sid = createSid()
|
||||
localStorage.setItem('api.sessionid', sid)
|
||||
localStorage.setItem(sid_key, sid)
|
||||
}
|
||||
return sid
|
||||
}
|
||||
|
||||
console.log("sid: ", getSid())
|
||||
//localStorage.setItem('api.sessionid', '')
|
||||
// TODO: clear sid - when?
|
||||
|
||||
async function dopoll(app: typeof appdata) {
|
||||
|
|
Loading…
Add table
Reference in a new issue