简写websocket的token验证代码,保持最小化修改

This commit is contained in:
老五 2025-06-12 18:58:20 +08:00
parent 46eadf7f8d
commit 10919439d9

View File

@ -23,24 +23,13 @@ export const actions: ActionTree<ServerState, RootState> = {
try {
let token = localStorage.getItem('token')
let data = {
const connection = await Vue.$socket.emitAndWait('server.connection.identify', {
client_name: 'mainsail',
version: rootState.packageVersion,
type: 'web',
url: 'https://github.com/mainsail-crew/mainsail',
}
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)
...(token ? { access_token: token }: {})
})
commit('setConnectionId', connection.connection_id)
} catch (e: any) {
if (e.message === 'Unauthorized') {