mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add authenticate function.
This commit is contained in:
parent
45c6c33647
commit
5c8c8c1330
@ -184,20 +184,28 @@
|
|||||||
Vue.set(this.state, 'authenticated', false)
|
Vue.set(this.state, 'authenticated', false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if is user logged in
|
if (!this.autologin) return
|
||||||
if (this.autologin) {
|
await this.authenticate()
|
||||||
const token = localStorage.getItem('neko_session')
|
|
||||||
if (token) {
|
|
||||||
this.api.setToken(token)
|
|
||||||
this.connection.setToken(token)
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.api.session.whoami()
|
if (!this.autoconnect) return
|
||||||
Vue.set(this.state, 'authenticated', true)
|
await this.connect()
|
||||||
|
}
|
||||||
|
|
||||||
if (this.autoconnect) {
|
public async authenticate(token?: string) {
|
||||||
await this.connect()
|
if (!token && this.autologin) {
|
||||||
}
|
token = localStorage.getItem('neko_session') ?? undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
if (token) {
|
||||||
|
this.api.setToken(token)
|
||||||
|
this.connection.setToken(token)
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.api.session.whoami()
|
||||||
|
Vue.set(this.state, 'authenticated', true)
|
||||||
|
|
||||||
|
if (token && this.autologin) {
|
||||||
|
localStorage.setItem('neko_session', token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,10 +225,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
Vue.set(this.state, 'authenticated', true)
|
Vue.set(this.state, 'authenticated', true)
|
||||||
|
|
||||||
if (this.autoconnect) {
|
|
||||||
await this.connect()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async logout() {
|
public async logout() {
|
||||||
@ -246,7 +250,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Refactor.
|
|
||||||
public async connect(video?: string) {
|
public async connect(video?: string) {
|
||||||
if (!this.state.authenticated) {
|
if (!this.state.authenticated) {
|
||||||
throw new Error('client not authenticated')
|
throw new Error('client not authenticated')
|
||||||
@ -312,7 +315,6 @@
|
|||||||
this.connection.setVideo(video)
|
this.connection.setVideo(video)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Refactor.
|
|
||||||
public setWebRTCAuto(auto: boolean = true) {
|
public setWebRTCAuto(auto: boolean = true) {
|
||||||
Vue.set(this.state.connection.webrtc, 'auto', auto)
|
Vue.set(this.state.connection.webrtc, 'auto', auto)
|
||||||
}
|
}
|
||||||
@ -363,7 +365,6 @@
|
|||||||
this.clear()
|
this.clear()
|
||||||
})
|
})
|
||||||
|
|
||||||
// webrtc
|
|
||||||
this.connection.webrtc.on('track', (event: RTCTrackEvent) => {
|
this.connection.webrtc.on('track', (event: RTCTrackEvent) => {
|
||||||
const { track, streams } = event
|
const { track, streams } = event
|
||||||
if (track.kind === 'audio') return
|
if (track.kind === 'audio') return
|
||||||
|
Loading…
Reference in New Issue
Block a user