♻️ refactor(auth): Refactor user authorization handling and improve error logging
This commit is contained in:
parent
cd59d44435
commit
68bc18f584
@ -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 (
|
||||
|
||||
@ -22,6 +22,7 @@ export default function Providers({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 5 * 1000,
|
||||
retry: false,
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
5
apps/admin/services/admin/typings.d.ts
vendored
5
apps/admin/services/admin/typings.d.ts
vendored
@ -613,11 +613,6 @@ declare namespace API {
|
||||
ip_register_limit_duration: number;
|
||||
};
|
||||
|
||||
type RelayConfig = {
|
||||
dispatch_mode: string;
|
||||
relay_nodes: NodeRelay[];
|
||||
};
|
||||
|
||||
type Response = {
|
||||
/** 状态码 */
|
||||
code?: number;
|
||||
|
||||
5
apps/admin/services/common/typings.d.ts
vendored
5
apps/admin/services/common/typings.d.ts
vendored
@ -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;
|
||||
|
||||
@ -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 (
|
||||
|
||||
@ -22,6 +22,7 @@ export default function Providers({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 5 * 1000,
|
||||
retry: false,
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
5
apps/user/services/common/typings.d.ts
vendored
5
apps/user/services/common/typings.d.ts
vendored
@ -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;
|
||||
|
||||
5
apps/user/services/user/typings.d.ts
vendored
5
apps/user/services/user/typings.d.ts
vendored
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user