简写websocket的token验证代码,保持最小化修改
This commit is contained in:
parent
46eadf7f8d
commit
10919439d9
@ -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') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user