add auto login for token.

This commit is contained in:
Miroslav Šedivý 2021-04-24 21:22:36 +02:00
parent edc4ea427d
commit 73d57f0294

View File

@ -194,6 +194,12 @@
// check if is user logged in // check if is user logged in
if (this.autologin) { if (this.autologin) {
const token = localStorage.getItem('neko_session')
if (token) {
this.api.setToken(token)
this.websocket.setToken(token)
}
this.api.session.whoami().then(() => { this.api.session.whoami().then(() => {
Vue.set(this.state.connection, 'authenticated', true) Vue.set(this.state.connection, 'authenticated', true)
this.websocket.connect() this.websocket.connect()
@ -210,6 +216,10 @@
if (res.data.token) { if (res.data.token) {
this.api.setToken(res.data.token) this.api.setToken(res.data.token)
this.websocket.setToken(res.data.token) this.websocket.setToken(res.data.token)
if (this.autologin) {
localStorage.setItem('neko_session', res.data.token)
}
} }
Vue.set(this.state.connection, 'authenticated', true) Vue.set(this.state.connection, 'authenticated', true)
@ -231,6 +241,10 @@
this.api.setToken('') this.api.setToken('')
this.websocket.setToken('') this.websocket.setToken('')
if (this.autologin) {
localStorage.removeItem('neko_session')
}
Vue.set(this.state.connection, 'authenticated', false) Vue.set(this.state.connection, 'authenticated', false)
} }
} }