Added redirect to / without login 🔓

This commit is contained in:
Chirag Bhalotia 2023-06-24 11:47:45 +05:30
parent a10de07f1c
commit 5afe2907f1
No known key found for this signature in database
GPG Key ID: F7F1F1FBFFD40427
1 changed files with 12 additions and 3 deletions

View File

@ -1,5 +1,7 @@
import { sidebarGroups } from '@/lib/sidebar';
import { cookies } from 'next/headers';
import Link from 'next/link';
import { redirect } from 'next/navigation';
import React from 'react';
interface DashboardLayoutProps {
@ -7,17 +9,24 @@ interface DashboardLayoutProps {
}
const Layout = ({ children }: DashboardLayoutProps) => {
const cookieList = cookies();
const apiKey = cookieList.has('apiKey');
const masterKey = cookieList.has('masterKey');
const instanceUrl = cookieList.has('instanceUrl');
if (!apiKey || !masterKey || !instanceUrl) redirect('/');
return (
<div className="flex h-screen">
<div className="sidebar w-full max-w-xs h-screen bg-black flex flex-col overflow-x-hidden overflow-y-auto">
{sidebarGroups.map((sidebarGrp, index) => {
return (
<div key={index} className="menu-group p-4">
<p className="title text-lg text-primary mb-2">{sidebarGrp.name}</p>
<p className="title text-lg text-primary mb-2">
{sidebarGrp.name}
</p>
{sidebarGrp.items.map((item, index) => {
return (
<Link
key={index}
key={index}
href={item.href}
className="p-2.5 block text-sm hover:bg-gray-900 w-full rounded-md"
>
@ -29,7 +38,7 @@ const Layout = ({ children }: DashboardLayoutProps) => {
);
})}
</div>
<main className='w-full h-full overflow-y-auto p-5'>{children}</main>
<main className="w-full h-full overflow-y-auto p-5">{children}</main>
</div>
);
};