feat: update authentication logic in App component to use new verification endpoint and streamline initial data fetching
This commit is contained in:
@@ -54,21 +54,14 @@
|
|||||||
const auth = localStorage.getItem('auth');
|
const auth = localStorage.getItem('auth');
|
||||||
if (auth) {
|
if (auth) {
|
||||||
try {
|
try {
|
||||||
// 使用 page 接口验证登录状态
|
// 使用新的验证接口检查登录状态
|
||||||
const response = await request.get<ApiResponse<PageResponse>>('/media/page', {
|
const response = await request.get<ApiResponse<{username: string}>>('/auth/verify');
|
||||||
params: {
|
|
||||||
type: 'game',
|
|
||||||
currentPage: 1,
|
|
||||||
pageSize: pageSize
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.data.code === 0) {
|
if (response.data.code === 0) {
|
||||||
isAuthenticated = true;
|
isAuthenticated = true;
|
||||||
error = '';
|
error = '';
|
||||||
// 设置初始数据
|
// 获取初始数据
|
||||||
mediaList = response.data.data.list;
|
await fetchMediaList();
|
||||||
totalItems = response.data.data.total;
|
|
||||||
} else {
|
} else {
|
||||||
// 如果认证失败,清除存储的认证信息
|
// 如果认证失败,清除存储的认证信息
|
||||||
localStorage.removeItem('auth');
|
localStorage.removeItem('auth');
|
||||||
@@ -129,21 +122,14 @@
|
|||||||
const auth = btoa(`${username}:${password}`);
|
const auth = btoa(`${username}:${password}`);
|
||||||
localStorage.setItem('auth', auth);
|
localStorage.setItem('auth', auth);
|
||||||
|
|
||||||
// 使用 page 接口验证登录
|
// 使用验证接口验证登录
|
||||||
const response = await request.get<ApiResponse<PageResponse>>('/media/page', {
|
const response = await request.get<ApiResponse<{username: string}>>('/auth/verify');
|
||||||
params: {
|
|
||||||
type: 'game',
|
|
||||||
currentPage: 1,
|
|
||||||
pageSize: pageSize
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.data.code === 0) {
|
if (response.data.code === 0) {
|
||||||
isAuthenticated = true;
|
isAuthenticated = true;
|
||||||
error = '';
|
error = '';
|
||||||
// 设置初始数据
|
// 获取初始数据
|
||||||
mediaList = response.data.data.list;
|
await fetchMediaList();
|
||||||
totalItems = response.data.data.total;
|
|
||||||
} else {
|
} else {
|
||||||
error = response.data.message || 'Invalid username or password';
|
error = response.data.message || 'Invalid username or password';
|
||||||
localStorage.removeItem('auth');
|
localStorage.removeItem('auth');
|
||||||
|
|||||||
Reference in New Issue
Block a user