Fixed problem when session not found

This commit is contained in:
Magnus Åhall 2024-01-06 11:40:58 +01:00
parent 7031c0100e
commit ddb49bad13
3 changed files with 106 additions and 96 deletions

2
go.mod
View File

@ -3,7 +3,7 @@ module notes
go 1.21.0 go 1.21.0
require ( require (
git.gibonuddevalla.se/go/webservice v0.1.1 git.gibonuddevalla.se/go/webservice v0.2.0
github.com/google/uuid v1.5.0 github.com/google/uuid v1.5.0
github.com/gorilla/websocket v1.5.0 github.com/gorilla/websocket v1.5.0
github.com/jmoiron/sqlx v1.3.5 github.com/jmoiron/sqlx v1.3.5

View File

@ -31,7 +31,7 @@ class App extends Component {
let app_el = document.getElementById('app') let app_el = document.getElementById('app')
if (!this.session.initialized) { if (!this.session.initialized) {
return html`<div>Validating session</div>` return
} }
if (!this.session.authenticated()) { if (!this.session.authenticated()) {
@ -130,8 +130,16 @@ class App extends Component {
.then(json => { .then(json => {
// An application level error occured // An application level error occured
if (!json.OK) { if (!json.OK) {
switch (json.Code) {
case '001-0001': // Session not found
this.session.reset()
location.href = '/'
break
default:
return reject({ app: json }) return reject({ app: json })
} }
}
return resolve(json) return resolve(json)
}) })
.catch(err => reject({ comm: err })) .catch(err => reject({ comm: err }))

View File

@ -32,9 +32,6 @@ export class Session {
this.UserID = res.Session.UserID // could be 0 this.UserID = res.Session.UserID // could be 0
this.initialized = true this.initialized = true
this.app.forceUpdate() this.app.forceUpdate()
} else {
// Session has probably expired. A new is required.
this.create()
} }
}) })
.catch(this.app.responseError) .catch(this.app.responseError)
@ -43,12 +40,17 @@ export class Session {
this.app.request('/_session/new', {}) this.app.request('/_session/new', {})
.then(res => { .then(res => {
this.UUID = res.Session.UUID this.UUID = res.Session.UUID
window.localStorage.setItem('session.UUID', this.Session.UUID) window.localStorage.setItem('session.UUID', this.UUID)
this.initialized = true this.initialized = true
this.app.forceUpdate() this.app.forceUpdate()
}) })
.catch(this.responseError) .catch(this.responseError)
}//}}} }//}}}
reset() {//{{{
window.localStorage.removeItem('session.UUID')
this.initialized = false
this.UserID = 0
}//}}}
authenticate(username, password) {//{{{ authenticate(username, password) {//{{{
this.app.login.current.authentication_failed.value = false this.app.login.current.authentication_failed.value = false