mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add auto login for token.
This commit is contained in:
parent
edc4ea427d
commit
73d57f0294
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user