Skip to content

Commit

Permalink
♻️ refactor(auth): Refactor user authorization handling and improve e…
Browse files Browse the repository at this point in the history
…rror logging
  • Loading branch information
web-ppanel committed Dec 30, 2024
1 parent cd59d44 commit 68bc18f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 35 deletions.
18 changes: 11 additions & 7 deletions apps/admin/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions apps/admin/components/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function Providers({
defaultOptions: {
queries: {
staleTime: 5 * 1000,
retry: false,
},
},
}),
Expand Down
5 changes: 0 additions & 5 deletions apps/admin/services/admin/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,6 @@ declare namespace API {
ip_register_limit_duration: number;
};

type RelayConfig = {
dispatch_mode: string;
relay_nodes: NodeRelay[];
};

type Response = {
/** 状态码 */
code?: number;
Expand Down
5 changes: 0 additions & 5 deletions apps/admin/services/common/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 16 additions & 8 deletions apps/user/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions apps/user/components/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default function Providers({
defaultOptions: {
queries: {
staleTime: 5 * 1000,
retry: false,
},
},
}),
Expand Down
5 changes: 0 additions & 5 deletions apps/user/services/common/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions apps/user/services/user/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 68bc18f

Please sign in to comment.