简写websocket的token验证代码,保持最小化修改
This commit is contained in:
parent
46eadf7f8d
commit
10919439d9
@ -23,24 +23,13 @@ export const actions: ActionTree<ServerState, RootState> = {
|
|||||||
try {
|
try {
|
||||||
let token = localStorage.getItem('token')
|
let token = localStorage.getItem('token')
|
||||||
|
|
||||||
let data = {
|
const connection = await Vue.$socket.emitAndWait('server.connection.identify', {
|
||||||
client_name: 'mainsail',
|
client_name: 'mainsail',
|
||||||
version: rootState.packageVersion,
|
version: rootState.packageVersion,
|
||||||
type: 'web',
|
type: 'web',
|
||||||
url: 'https://github.com/mainsail-crew/mainsail',
|
url: 'https://github.com/mainsail-crew/mainsail',
|
||||||
}
|
...(token ? { access_token: token }: {})
|
||||||
|
})
|
||||||
let dataWithToken = {
|
|
||||||
client_name: 'mainsail',
|
|
||||||
version: rootState.packageVersion,
|
|
||||||
type: 'web',
|
|
||||||
url: 'https://github.com/mainsail-crew/mainsail',
|
|
||||||
access_token: token
|
|
||||||
}
|
|
||||||
|
|
||||||
let wsData = token ? dataWithToken : data;
|
|
||||||
|
|
||||||
const connection = await Vue.$socket.emitAndWait('server.connection.identify', wsData)
|
|
||||||
commit('setConnectionId', connection.connection_id)
|
commit('setConnectionId', connection.connection_id)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (e.message === 'Unauthorized') {
|
if (e.message === 'Unauthorized') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user