简写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 { 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') {