mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 17:49:16 +00:00
fix: 401 errors on user management page
This commit is contained in:
@@ -192,7 +192,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
import axios from 'axios'
|
import { apiClient } from '@/config/api'
|
||||||
import { showToast } from '@/utils/toast'
|
import { showToast } from '@/utils/toast'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -221,15 +221,15 @@ const handleSubmit = async () => {
|
|||||||
error.value = ''
|
error.value = ''
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.patch(`/users/${props.user.id}/role`, {
|
const response = await apiClient.patch(`/users/${props.user.id}/role`, {
|
||||||
role: selectedRole.value
|
role: selectedRole.value
|
||||||
})
|
})
|
||||||
|
|
||||||
if (response.data.success) {
|
if (response.success) {
|
||||||
showToast(`User role updated to ${selectedRole.value}`, 'success')
|
showToast(`User role updated to ${selectedRole.value}`, 'success')
|
||||||
emit('updated')
|
emit('updated')
|
||||||
} else {
|
} else {
|
||||||
error.value = response.data.message || 'Failed to update user role'
|
error.value = response.message || 'Failed to update user role'
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Update user role error:', err)
|
console.error('Update user role error:', err)
|
||||||
|
|||||||
@@ -347,7 +347,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
import axios from 'axios'
|
import { apiClient } from '@/config/api'
|
||||||
import { showToast } from '@/utils/toast'
|
import { showToast } from '@/utils/toast'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -394,18 +394,18 @@ const loadUsageStats = async () => {
|
|||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const [statsResponse, userResponse] = await Promise.all([
|
const [statsResponse, userResponse] = await Promise.all([
|
||||||
axios.get(`/users/${props.user.id}/usage-stats`, {
|
apiClient.get(`/users/${props.user.id}/usage-stats`, {
|
||||||
params: { period: selectedPeriod.value }
|
params: { period: selectedPeriod.value }
|
||||||
}),
|
}),
|
||||||
axios.get(`/users/${props.user.id}`)
|
apiClient.get(`/users/${props.user.id}`)
|
||||||
])
|
])
|
||||||
|
|
||||||
if (statsResponse.data.success) {
|
if (statsResponse.success) {
|
||||||
usageStats.value = statsResponse.data.stats
|
usageStats.value = statsResponse.stats
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userResponse.data.success) {
|
if (userResponse.success) {
|
||||||
userDetails.value = userResponse.data.user
|
userDetails.value = userResponse.user
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load user usage stats:', error)
|
console.error('Failed to load user usage stats:', error)
|
||||||
|
|||||||
@@ -149,6 +149,24 @@ class ApiClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PATCH 请求
|
||||||
|
async patch(url, data = null, options = {}) {
|
||||||
|
const fullUrl = createApiUrl(url)
|
||||||
|
const config = this.buildConfig({
|
||||||
|
...options,
|
||||||
|
method: 'PATCH',
|
||||||
|
body: data ? JSON.stringify(data) : undefined
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(fullUrl, config)
|
||||||
|
return await this.handleResponse(response)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('API PATCH Error:', error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DELETE 请求
|
// DELETE 请求
|
||||||
async delete(url, options = {}) {
|
async delete(url, options = {}) {
|
||||||
const fullUrl = createApiUrl(url)
|
const fullUrl = createApiUrl(url)
|
||||||
|
|||||||
@@ -454,7 +454,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
import axios from 'axios'
|
import { apiClient } from '@/config/api'
|
||||||
import { showToast } from '@/utils/toast'
|
import { showToast } from '@/utils/toast'
|
||||||
import { debounce } from 'lodash-es'
|
import { debounce } from 'lodash-es'
|
||||||
import UserUsageStatsModal from '@/components/admin/UserUsageStatsModal.vue'
|
import UserUsageStatsModal from '@/components/admin/UserUsageStatsModal.vue'
|
||||||
@@ -533,21 +533,21 @@ const loadUsers = async () => {
|
|||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const [usersResponse, statsResponse] = await Promise.all([
|
const [usersResponse, statsResponse] = await Promise.all([
|
||||||
axios.get('/users', {
|
apiClient.get('/users', {
|
||||||
params: {
|
params: {
|
||||||
role: selectedRole.value || undefined,
|
role: selectedRole.value || undefined,
|
||||||
isActive: selectedStatus.value !== '' ? selectedStatus.value : undefined
|
isActive: selectedStatus.value !== '' ? selectedStatus.value : undefined
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
axios.get('/users/stats/overview')
|
apiClient.get('/users/stats/overview')
|
||||||
])
|
])
|
||||||
|
|
||||||
if (usersResponse.data.success) {
|
if (usersResponse.success) {
|
||||||
users.value = usersResponse.data.users
|
users.value = usersResponse.users
|
||||||
}
|
}
|
||||||
|
|
||||||
if (statsResponse.data.success) {
|
if (statsResponse.success) {
|
||||||
userStats.value = statsResponse.data.stats
|
userStats.value = statsResponse.stats
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load users:', error)
|
console.error('Failed to load users:', error)
|
||||||
@@ -605,11 +605,11 @@ const handleConfirmAction = async () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (action === 'toggleStatus') {
|
if (action === 'toggleStatus') {
|
||||||
const response = await axios.patch(`/users/${user.id}/status`, {
|
const response = await apiClient.patch(`/users/${user.id}/status`, {
|
||||||
isActive: !user.isActive
|
isActive: !user.isActive
|
||||||
})
|
})
|
||||||
|
|
||||||
if (response.data.success) {
|
if (response.success) {
|
||||||
const userIndex = users.value.findIndex((u) => u.id === user.id)
|
const userIndex = users.value.findIndex((u) => u.id === user.id)
|
||||||
if (userIndex !== -1) {
|
if (userIndex !== -1) {
|
||||||
users.value[userIndex].isActive = !user.isActive
|
users.value[userIndex].isActive = !user.isActive
|
||||||
@@ -617,10 +617,10 @@ const handleConfirmAction = async () => {
|
|||||||
showToast(`User ${user.isActive ? 'disabled' : 'enabled'} successfully`, 'success')
|
showToast(`User ${user.isActive ? 'disabled' : 'enabled'} successfully`, 'success')
|
||||||
}
|
}
|
||||||
} else if (action === 'disableKeys') {
|
} else if (action === 'disableKeys') {
|
||||||
const response = await axios.post(`/users/${user.id}/disable-keys`)
|
const response = await apiClient.post(`/users/${user.id}/disable-keys`)
|
||||||
|
|
||||||
if (response.data.success) {
|
if (response.success) {
|
||||||
showToast(`Disabled ${response.data.disabledCount} API keys`, 'success')
|
showToast(`Disabled ${response.disabledCount} API keys`, 'success')
|
||||||
await loadUsers() // Refresh to get updated counts
|
await loadUsers() // Refresh to get updated counts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user