Skip to content

Commit

Permalink
created .env.production file
Browse files Browse the repository at this point in the history
  • Loading branch information
bduran04 committed Sep 18, 2024
1 parent e0f13c6 commit 220bbb2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dev
node_modules
.env.local
.next
.env.production
29 changes: 29 additions & 0 deletions app/dashboard/DashboardServer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';
import { Container, Typography, Box } from '@mui/material';
import ExampleEquations from '../components/ExampleEquations';
import DashboardClient from './DashboardClient';

interface UserData {
id: string;
email: string;
fullName: string;
lastName: string;
}

const DashboardServer = async () => {
const cookieStore = cookies().get('user-data');

if (!cookieStore) {
return <div>Redirecting...</div>;
}

try {
const userData: UserData = JSON.parse(cookieStore.value);
return <DashboardClient userData={userData} />;
} catch {
redirect('/');
}
};

export default DashboardServer;
41 changes: 4 additions & 37 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,7 @@
import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';
import DashboardClient from './DashboardClient';
import DashboardServer from './DashboardServer';

interface UserData {
id: string;
email: string;
fullName: string;
lastName: string;
}

const getUserData = (): UserData | null => {
const cookieStore = cookies();
const userDataCookie = cookieStore.get('user-data');

if (userDataCookie) {
try {
return JSON.parse(userDataCookie.value);
} catch (error) {
console.error('Failed to parse user data cookie', error);
return null;
}
}

return null;
};

const DashboardPage = () => {
const userData = getUserData();

if (!userData) {
redirect('/'); // Redirect to homepage if no user data is found
}

return (
<DashboardClient userData={userData!} />
);
const Page = () => {
return <DashboardServer />;
};

export default DashboardPage;
export default Page;

0 comments on commit 220bbb2

Please sign in to comment.