Update user data fallback and theme handling

This commit adds a fallback mechanism to handle `null` user values in the site header account section. Previously, if `user.data` was `null`, the code could fail. Now, it checks for valid `user.data` before proceeding. For the layout section, it now includes a separate condition for 'light' theme, providing a clear distinction between 'dark'
This commit is contained in:
giancarlo
2024-04-16 17:15:22 +08:00
parent 35291975a6
commit f2be1b80f4
2 changed files with 8 additions and 5 deletions

View File

@@ -39,13 +39,14 @@ export function SiteHeaderAccountSection({
function SuspendedPersonalAccountDropdown(props: { user: User | null }) {
const signOut = useSignOut();
const user = useUser(props.user);
const userData = user.data ?? props.user ?? null;
if (user.data) {
if (userData) {
return (
<PersonalAccountDropdown
paths={paths}
features={features}
user={user.data}
user={userData}
signOutRequested={() => signOut.mutateAsync()}
/>
);

View File

@@ -51,14 +51,16 @@ export default async function RootLayout({
function getClassName(theme?: string) {
const dark = theme === 'dark';
const light = theme === 'light';
return cn(
'min-h-screen bg-background antialiased',
{
dark,
},
sans.variable,
heading.variable,
{
dark,
light,
},
);
}