优化 JWT 令牌的存储和使用逻辑;调整布局样式和组件属性

This commit is contained in:
2025-04-06 23:09:48 +08:00
parent d5c9e663da
commit eb306b66b0
14 changed files with 144 additions and 140 deletions

View File

@@ -1,4 +1,4 @@
import { useAccount } from '@/api/account'
import { cookie, useAccount } from '@/api/account'
import {
BaseRTCClient,
MasterRTCClient,
@@ -25,7 +25,6 @@ export const useWebRTC = defineStore('WebRTC', () => {
function send(event: string, data: any) {
client.value?.send(event, data)
}
const cookie = useStorage('JWT_Token', '')
const route = useRoute()
async function Init(type: 'master' | 'slave') {
if (isInitializing) {
@@ -38,7 +37,7 @@ export const useWebRTC = defineStore('WebRTC', () => {
{ ifAvailable: true },
async (lock) => {
if (lock) {
if (!cookie.value && !route.query.token) {
if (!cookie.value.cookie && !route.query.token) {
console.log('[RTC] 未登录, 跳过RTC初始化')
return
}

View File

@@ -6,7 +6,7 @@ import { compress } from 'brotli-compress';
import { format } from 'date-fns';
import * as signalR from '@microsoft/signalr';
import * as msgpack from '@microsoft/signalr-protocol-msgpack';
import { useAccount } from '@/api/account'; // 假设账户信息路径
import { cookie, useAccount } from '@/api/account'; // 假设账户信息路径
import { BASE_HUB_URL, isDev } from '@/data/constants'; // 假设常量路径
import BaseDanmakuClient from '@/data/DanmakuClients/BaseDanmakuClient'; // 假设弹幕客户端基类路径
import DirectClient, { DirectClientAuthInfo } from '@/data/DanmakuClients/DirectClient'; // 假设直连客户端路径
@@ -16,7 +16,6 @@ import { getEventType, recordEvent, streamingInfo } from '@/client/data/info';
import { useWebRTC } from './useRTC';
export const useWebFetcher = defineStore('WebFetcher', () => {
const cookie = useLocalStorage('JWT_Token', '');
const route = useRoute();
const account = useAccount();
const rtc = useWebRTC();
@@ -220,7 +219,7 @@ export const useWebFetcher = defineStore('WebFetcher', () => {
logInfo(prefix.value + '正在连接到 vtsuru 服务器...');
const connection = new signalR.HubConnectionBuilder()
.withUrl(BASE_HUB_URL + 'web-fetcher?token=' + (route.query.token ?? account.value.token), { // 使用 account.token
headers: { Authorization: `Bearer ${cookie.value}` },
headers: { Authorization: `Bearer ${cookie.value?.cookie}` },
skipNegotiation: true,
transport: signalR.HttpTransportType.WebSockets
})