修改登录逻辑

默认先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() this.appHeight()
window.addEventListener('resize', this.appHeight) window.addEventListener('resize', this.appHeight)
window.addEventListener('orientationchange', this.appHeight) window.addEventListener('orientationchange', this.appHeight)
if (!localStorage.getItem('token')) {
this.$refs.loginRef.showDialog=true
}
} }
} }
</script> </script>

View File

@ -21,19 +21,26 @@ export const actions: ActionTree<ServerState, RootState> = {
// identify client // identify client
try { try {
let token = null let token = localStorage.getItem('token')
if (localStorage.getItem('token')) {
token = localStorage.getItem('token') let data = {
} else { client_name: 'mainsail',
token = null 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', 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',
access_token: token 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') {