update
This commit is contained in:
@@ -4,7 +4,7 @@ import Image from 'next/image';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Season } from '@/app/generated/prisma/enums';
|
||||
|
||||
interface UserInfo {
|
||||
interface userInfo {
|
||||
id: number;
|
||||
osuid: number;
|
||||
username: string;
|
||||
@@ -19,12 +19,16 @@ interface UserInfo {
|
||||
approved: boolean;
|
||||
seed: number;
|
||||
}
|
||||
interface RegisterUserCardProps {
|
||||
userInfo?: userInfo;
|
||||
onRefresh?: () => void;
|
||||
}
|
||||
|
||||
export default function RegisterUserCard() {
|
||||
export default function RegisterUserCard({ userInfo: initialUserInfo, onRefresh }: RegisterUserCardProps) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [success, setSuccess] = useState<string | null>(null);
|
||||
const [userInfo, setUserInfo] = useState<UserInfo | null>(null);
|
||||
const [userInfo, setUserInfo] = useState<userInfo | null>(null);
|
||||
const [searchType, setSearchType] = useState<'osuid' | 'username'>('osuid');
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
const [updateData, setUpdateData] = useState({
|
||||
@@ -37,78 +41,6 @@ export default function RegisterUserCard() {
|
||||
country_rank: 0,
|
||||
});
|
||||
|
||||
// 检查URL参数,处理OAuth回调结果,并检查当前登录状态
|
||||
useEffect(() => {
|
||||
const checkCurrentUser = async () => {
|
||||
console.log('Checking current user session...');
|
||||
try {
|
||||
const response = await fetch('/api/user/me', {
|
||||
credentials: 'include', // 确保发送 cookie
|
||||
});
|
||||
|
||||
console.log('API response status:', response.status);
|
||||
|
||||
if (response.ok) {
|
||||
const user = await response.json();
|
||||
console.log('User found:', user.username);
|
||||
|
||||
setUserInfo({
|
||||
id: user.id,
|
||||
osuid: user.osuid,
|
||||
username: user.username,
|
||||
avatar_url: user.avatar_url,
|
||||
cover_url: user.cover_url,
|
||||
country_code: user.country_code,
|
||||
pp: user.pp,
|
||||
global_rank: user.global_rank,
|
||||
country_rank: user.country_rank,
|
||||
seasonal: user.seasonal,
|
||||
userState: user.userState,
|
||||
approved: user.approved === 1,
|
||||
seed: user.seed,
|
||||
});
|
||||
|
||||
setUpdateData({
|
||||
username: user.username,
|
||||
avatar_url: user.avatar_url || '',
|
||||
cover_url: user.cover_url || '',
|
||||
country_code: user.country_code,
|
||||
pp: user.pp,
|
||||
global_rank: user.global_rank,
|
||||
country_rank: user.country_rank,
|
||||
});
|
||||
} else {
|
||||
console.log('User not authenticated or API error:', response.status);
|
||||
}
|
||||
} catch (err) {
|
||||
// 忽略错误,用户可能未登录
|
||||
console.log('Error checking user session:', err);
|
||||
}
|
||||
|
||||
// 检查URL参数,处理OAuth回调结果
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const successParam = params.get('success');
|
||||
const usernameParam = params.get('username');
|
||||
const osuidParam = params.get('osuid');
|
||||
const errorParam = params.get('error');
|
||||
|
||||
if (successParam === 'true' && usernameParam && osuidParam) {
|
||||
setSuccess(`用户 ${usernameParam} (osuid: ${osuidParam}) 注册/登录成功!`);
|
||||
// 清空URL参数
|
||||
const newUrl = window.location.pathname;
|
||||
window.history.replaceState({}, '', newUrl);
|
||||
}
|
||||
|
||||
if (errorParam) {
|
||||
setError(decodeURIComponent(errorParam));
|
||||
// 清空URL参数
|
||||
const newUrl = window.location.pathname;
|
||||
window.history.replaceState({}, '', newUrl);
|
||||
}
|
||||
};
|
||||
|
||||
checkCurrentUser();
|
||||
}, []);
|
||||
|
||||
const handleOsuLogin = () => {
|
||||
window.location.href = '/api/auth/getAuthUrl';
|
||||
@@ -358,7 +290,6 @@ export default function RegisterUserCard() {
|
||||
退出登录
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
|
||||
<div>
|
||||
<p><strong>ID:</strong> {userInfo.id}</p>
|
||||
|
||||
@@ -1,12 +1,27 @@
|
||||
import TournamentConfigCard from '@/app/debug/components/TournamentConfigCard';
|
||||
import RegisterUserCard from '@/app/debug/components/RegisterUserCard';
|
||||
|
||||
import { useUserData,useConfigData } from '@/app/lib/FetcherApi';
|
||||
|
||||
export default function DebugPage() {
|
||||
const {
|
||||
userData,
|
||||
isLoading:isUserLoading,
|
||||
isError:isUserError,
|
||||
mutate:mutateUser
|
||||
} = useUserData();
|
||||
const {
|
||||
configData,
|
||||
isLoading:isConfigLoading,
|
||||
isError:isConfigError,
|
||||
mutate:mutateConfig
|
||||
} = useConfigData();
|
||||
|
||||
return (
|
||||
<div className="container mx-auto p-6">
|
||||
<h1 className="text-3xl font-bold mb-6">调试页面</h1>
|
||||
|
||||
<RegisterUserCard />
|
||||
<RegisterUserCard userInfo={userData} />
|
||||
<TournamentConfigCard />
|
||||
|
||||
</div>
|
||||
|
||||
32
app/lib/FetcherApi.ts
Normal file
32
app/lib/FetcherApi.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import useSWR from "swr";
|
||||
|
||||
const fetcher = (...url: Parameters<typeof fetch>) => fetch(...url).then((r) => r.json())
|
||||
|
||||
export function useUserData(){
|
||||
const { data, error, isLoading, mutate } = useSWR('/api/user/me', fetcher);
|
||||
return {
|
||||
userData: data,
|
||||
isLoading,
|
||||
isError: error,
|
||||
mutate,
|
||||
};
|
||||
}
|
||||
|
||||
// export function logoutUser(){
|
||||
// const { error, isLoading, mutate } = useSWR('/api/auth/getAuthUrl', fetcher);
|
||||
// return {
|
||||
// isLoading,
|
||||
// isError: error,
|
||||
// mutate,
|
||||
// };
|
||||
// }
|
||||
|
||||
export function useConfigData(){
|
||||
const { data, error, isLoading, mutate } = useSWR('/api/config',fetcher);
|
||||
return {
|
||||
configData: data,
|
||||
isLoading,
|
||||
isError: error,
|
||||
mutate,
|
||||
};
|
||||
}
|
||||
34
package-lock.json
generated
34
package-lock.json
generated
@@ -15,7 +15,8 @@
|
||||
"@prisma/extension-accelerate": "^3.0.1",
|
||||
"next": "16.1.6",
|
||||
"react": "19.2.3",
|
||||
"react-dom": "19.2.3"
|
||||
"react-dom": "19.2.3",
|
||||
"swr": "^2.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4",
|
||||
@@ -3700,6 +3701,15 @@
|
||||
"node": ">=0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/dequal": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmmirror.com/dequal/-/dequal-2.0.3.tgz",
|
||||
"integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/destr": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/destr/-/destr-2.0.5.tgz",
|
||||
@@ -7838,6 +7848,19 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/swr": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmmirror.com/swr/-/swr-2.4.0.tgz",
|
||||
"integrity": "sha512-sUlC20T8EOt1pHmDiqueUWMmRRX03W7w5YxovWX7VR2KHEPCTMly85x05vpkP5i6Bu4h44ePSMD9Tc+G2MItFw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dequal": "^2.0.3",
|
||||
"use-sync-external-store": "^1.6.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tailwindcss": {
|
||||
"version": "4.1.18",
|
||||
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.1.18.tgz",
|
||||
@@ -8226,6 +8249,15 @@
|
||||
"punycode": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/use-sync-external-store": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmmirror.com/use-sync-external-store/-/use-sync-external-store-1.6.0.tgz",
|
||||
"integrity": "sha512-Pp6GSwGP/NrPIrxVFAIkOQeyw8lFenOHijQWkUTrDvrF4ALqylP2C/KCkeS9dpUM3KvYRQhna5vt7IL95+ZQ9w==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/uuid": {
|
||||
"version": "8.3.2",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
"@prisma/extension-accelerate": "^3.0.1",
|
||||
"next": "16.1.6",
|
||||
"react": "19.2.3",
|
||||
"react-dom": "19.2.3"
|
||||
"react-dom": "19.2.3",
|
||||
"swr": "^2.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/postcss": "^4",
|
||||
|
||||
Reference in New Issue
Block a user