mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-06 18:36:55 +08:00
fix auth login logic
This commit is contained in:
@@ -17,10 +17,10 @@ export const useAuthStore = defineStore('BiliAuth', () => {
|
||||
token: string
|
||||
}[]
|
||||
>('Bili.Auth.Tokens', [])
|
||||
const biliToken = useStorage<string>('Bili.Auth.Selected', null)
|
||||
const currentToken = useStorage<string>('Bili.Auth.Selected', null)
|
||||
|
||||
const isLoading = ref(false)
|
||||
const isAuthed = computed(() => biliToken.value != null && biliToken.value.length > 0)
|
||||
const isAuthed = computed(() => currentToken.value != null && currentToken.value.length > 0)
|
||||
|
||||
async function setCurrentAuth(token: string) {
|
||||
if (!token) {
|
||||
@@ -28,7 +28,7 @@ export const useAuthStore = defineStore('BiliAuth', () => {
|
||||
return
|
||||
}
|
||||
biliAuth.value = {} as BiliAuthModel
|
||||
biliToken.value = token
|
||||
currentToken.value = token
|
||||
await getAuthInfo()
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export const useAuthStore = defineStore('BiliAuth', () => {
|
||||
if (index >= 0) {
|
||||
biliTokens.value[index] = {
|
||||
id: biliAuth.value.id,
|
||||
token: biliToken.value,
|
||||
token: currentToken.value,
|
||||
name: biliAuth.value.name,
|
||||
uId: biliAuth.value.userId,
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export const useAuthStore = defineStore('BiliAuth', () => {
|
||||
} else {
|
||||
biliTokens.value.push({
|
||||
id: biliAuth.value.id,
|
||||
token: biliToken.value,
|
||||
token: currentToken.value,
|
||||
name: biliAuth.value.name,
|
||||
uId: biliAuth.value.userId,
|
||||
})
|
||||
@@ -75,14 +75,14 @@ export const useAuthStore = defineStore('BiliAuth', () => {
|
||||
function QueryBiliAuthGetAPI<T>(url: string, params?: any, headers?: [string, string][]) {
|
||||
headers ??= []
|
||||
if (headers.find((h) => h[0] == 'Bili-Auth') == null) {
|
||||
headers.push(['Bili-Auth', biliToken.value ?? ''])
|
||||
headers.push(['Bili-Auth', currentToken.value ?? ''])
|
||||
}
|
||||
return QueryGetAPI<T>(url, params, headers)
|
||||
}
|
||||
function QueryBiliAuthPostAPI<T>(url: string, body?: unknown, headers?: [string, string][]) {
|
||||
headers ??= []
|
||||
if (headers.find((h) => h[0] == 'Bili-Auth') == null) {
|
||||
headers.push(['Bili-Auth', biliToken.value ?? ''])
|
||||
headers.push(['Bili-Auth', currentToken.value ?? ''])
|
||||
}
|
||||
return QueryPostAPI<T>(url, body, headers)
|
||||
}
|
||||
@@ -123,7 +123,7 @@ export const useAuthStore = defineStore('BiliAuth', () => {
|
||||
|
||||
return {
|
||||
biliAuth,
|
||||
biliToken,
|
||||
biliToken: currentToken,
|
||||
biliTokens,
|
||||
isLoading,
|
||||
isAuthed,
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
} from 'naive-ui'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { useAuthStore } from '@/store/useAuthStore'
|
||||
|
||||
type AuthStartModel = {
|
||||
code: string
|
||||
@@ -35,11 +36,12 @@ type AuthStartModel = {
|
||||
const message = useMessage()
|
||||
|
||||
const guidKey = useStorage('Bili.Auth.Key', uuidv4())
|
||||
const biliToken = useStorage<string>('Bili.Auth.Token', null)
|
||||
const currentToken = useStorage<string>('Bili.Auth.Selected', null)
|
||||
const useAuth = useAuthStore()
|
||||
|
||||
const startModel = ref<AuthStartModel>()
|
||||
|
||||
const currentStep = ref(biliToken.value ? 2 : 0)
|
||||
const currentStep = ref(currentToken.value ? 2 : 0)
|
||||
|
||||
const isStart = computed(() => {
|
||||
return currentStep.value > 0
|
||||
@@ -76,7 +78,9 @@ async function checkStatus() {
|
||||
clearInterval(timer.value)
|
||||
message.success('认证成功')
|
||||
|
||||
biliToken.value = data.data as string
|
||||
currentToken.value = data.data as string
|
||||
useAuth.getAuthInfo()
|
||||
|
||||
currentStep.value = 2
|
||||
|
||||
return true
|
||||
@@ -106,7 +110,7 @@ function copyCode() {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (!biliToken.value) {
|
||||
if (!currentToken.value) {
|
||||
if (await checkStatus()) {
|
||||
currentStep.value = 1
|
||||
timer.value = setInterval(checkStatus, 5000)
|
||||
@@ -182,7 +186,7 @@ onMounted(async () => {
|
||||
<NText> 你的登陆链接为: </NText>
|
||||
<NInputGroup>
|
||||
<NInput
|
||||
:value="`https://vtsuru.live/bili-user?auth=${biliToken}`"
|
||||
:value="`https://vtsuru.live/bili-user?auth=${currentToken}`"
|
||||
type="textarea"
|
||||
:allow-input="() => false"
|
||||
/>
|
||||
@@ -195,7 +199,7 @@ onMounted(async () => {
|
||||
() => {
|
||||
currentStep = 0
|
||||
//@ts-ignore
|
||||
biliToken = null
|
||||
currentToken = null
|
||||
guidKey = uuidv4()
|
||||
}
|
||||
"
|
||||
|
||||
@@ -110,6 +110,7 @@ onMounted(async () => {
|
||||
const route = useRoute()
|
||||
if (route.query.auth) {
|
||||
useAuth.biliToken = route.query.auth as string
|
||||
console.log(route.query.auth)
|
||||
}
|
||||
if (biliAuth.value?.id < 0) {
|
||||
isLoading.value = true
|
||||
|
||||
Reference in New Issue
Block a user