修改登录逻辑

默认先websoket鉴权判断是否需要登录
This commit is contained in:
老五 2025-06-12 18:38:19 +08:00
parent 97cb80e556
commit 46eadf7f8d
2 changed files with 14 additions and 10 deletions

View File

@ -403,9 +403,6 @@ export default class App extends Mixins(BaseMixin, ThemeMixin) {
this.appHeight()
window.addEventListener('resize', this.appHeight)
window.addEventListener('orientationchange', this.appHeight)
if (!localStorage.getItem('token')) {
this.$refs.loginRef.showDialog=true
}
}
}
</script>

View File

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