♻️ refactor(auth): Refactor user authorization handling and improve error logging

This commit is contained in:
web@ppanel 2024-12-30 22:41:12 +07:00
parent cd59d44435
commit 68bc18f584
8 changed files with 29 additions and 35 deletions

View File

@ -75,6 +75,8 @@ export default async function RootLayout({
}: Readonly<{
children: React.ReactNode;
}>) {
const Authorization = (await cookies()).get('Authorization')?.value;
const locale = await getLocale();
const messages = await getMessages();
@ -86,13 +88,15 @@ export default async function RootLayout({
console.log('Error fetching global config:', error);
}
try {
user = await currentUser({
skipErrorHandler: true,
Authorization: (await cookies()).get('Authorization')?.value,
}).then((res) => res.data.data);
} catch (error) {
console.log('Error fetching current user:', error);
if (Authorization) {
try {
user = await currentUser({
skipErrorHandler: true,
Authorization,
}).then((res) => res.data.data);
} catch (error) {
console.log('Error fetching current user:', error);
}
}
return (

View File

@ -22,6 +22,7 @@ export default function Providers({
defaultOptions: {
queries: {
staleTime: 5 * 1000,
retry: false,
},
},
}),

View File

@ -613,11 +613,6 @@ declare namespace API {
ip_register_limit_duration: number;
};
type RelayConfig = {
dispatch_mode: string;
relay_nodes: NodeRelay[];
};
type Response = {
/** 状态码 */
code?: number;

View File

@ -222,11 +222,6 @@ declare namespace API {
ip_register_limit_duration: number;
};
type RelayConfig = {
dispatch_mode: string;
relay_nodes: NodeRelay[];
};
type ResetPasswordRequest = {
email: string;
password: string;

View File

@ -69,7 +69,13 @@ export const viewport: Viewport = {
],
};
export default async function RootLayout({ children }: { children: React.ReactNode }) {
export default async function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
const Authorization = (await cookies()).get('Authorization')?.value;
const locale = await getLocale();
const messages = await getMessages();
@ -81,13 +87,15 @@ export default async function RootLayout({ children }: { children: React.ReactNo
console.log('Error fetching global config:', error);
}
try {
user = await queryUserInfo({
skipErrorHandler: true,
Authorization: (await cookies()).get('Authorization')?.value,
}).then((res) => res.data.data);
} catch (error) {
console.log('Error fetching user info:', error);
if (Authorization) {
try {
user = await queryUserInfo({
skipErrorHandler: true,
Authorization,
}).then((res) => res.data.data);
} catch (error) {
console.log('Error fetching user info:', error);
}
}
return (

View File

@ -22,6 +22,7 @@ export default function Providers({
defaultOptions: {
queries: {
staleTime: 5 * 1000,
retry: false,
},
},
}),

View File

@ -222,11 +222,6 @@ declare namespace API {
ip_register_limit_duration: number;
};
type RelayConfig = {
dispatch_mode: string;
relay_nodes: NodeRelay[];
};
type ResetPasswordRequest = {
email: string;
password: string;

View File

@ -358,11 +358,6 @@ declare namespace API {
ip_register_limit_duration: number;
};
type RelayConfig = {
dispatch_mode: string;
relay_nodes: NodeRelay[];
};
type RenewalOrderRequest = {
subscribe_id: number;
quantity: number;