Refactor user authorization in AdminSidebar
The commit simplifies user authorization in 'AdminSidebar' component by removing unnecessary imports and functions and passing user directly as a prop instead. This change optimizes code readability and makes user authorization more efficient.
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
import { redirect } from 'next/navigation';
|
import { User } from '@supabase/supabase-js';
|
||||||
|
|
||||||
import { Home, Users } from 'lucide-react';
|
import { Home, Users } from 'lucide-react';
|
||||||
|
|
||||||
import { requireUser } from '@kit/supabase/require-user';
|
|
||||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
|
||||||
import {
|
import {
|
||||||
Sidebar,
|
Sidebar,
|
||||||
SidebarContent,
|
SidebarContent,
|
||||||
@@ -14,14 +12,7 @@ import {
|
|||||||
import { AppLogo } from '~/components/app-logo';
|
import { AppLogo } from '~/components/app-logo';
|
||||||
import { ProfileAccountDropdownContainer } from '~/components/personal-account-dropdown-container';
|
import { ProfileAccountDropdownContainer } from '~/components/personal-account-dropdown-container';
|
||||||
|
|
||||||
export async function AdminSidebar() {
|
export function AdminSidebar(props: { user: User }) {
|
||||||
const client = getSupabaseServerActionClient();
|
|
||||||
const user = await requireUser(client);
|
|
||||||
|
|
||||||
if (user.error) {
|
|
||||||
redirect(user.redirectTo);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sidebar>
|
<Sidebar>
|
||||||
<SidebarContent className={'py-4'}>
|
<SidebarContent className={'py-4'}>
|
||||||
@@ -44,7 +35,7 @@ export async function AdminSidebar() {
|
|||||||
</SidebarContent>
|
</SidebarContent>
|
||||||
|
|
||||||
<SidebarContent className={'absolute bottom-4'}>
|
<SidebarContent className={'absolute bottom-4'}>
|
||||||
<ProfileAccountDropdownContainer user={user.data} collapsed={false} />
|
<ProfileAccountDropdownContainer user={props.user} collapsed={false} />
|
||||||
</SidebarContent>
|
</SidebarContent>
|
||||||
</Sidebar>
|
</Sidebar>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,16 +2,19 @@ import { Page, PageMobileNavigation, PageNavigation } from '@kit/ui/page';
|
|||||||
|
|
||||||
import { AdminSidebar } from '~/admin/_components/admin-sidebar';
|
import { AdminSidebar } from '~/admin/_components/admin-sidebar';
|
||||||
import { AdminMobileNavigation } from '~/admin/_components/mobile-navigation';
|
import { AdminMobileNavigation } from '~/admin/_components/mobile-navigation';
|
||||||
|
import { requireUserInServerComponent } from '~/lib/server/require-user-in-server-component';
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
title: `Super Admin`,
|
title: `Super Admin`,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function AdminLayout(props: React.PropsWithChildren) {
|
export default async function AdminLayout(props: React.PropsWithChildren) {
|
||||||
|
const user = await requireUserInServerComponent();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page style={'sidebar'}>
|
<Page style={'sidebar'}>
|
||||||
<PageNavigation>
|
<PageNavigation>
|
||||||
<AdminSidebar />
|
<AdminSidebar user={user} />
|
||||||
</PageNavigation>
|
</PageNavigation>
|
||||||
|
|
||||||
<PageMobileNavigation>
|
<PageMobileNavigation>
|
||||||
|
|||||||
Reference in New Issue
Block a user