-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ dev | |
node_modules | ||
.env.local | ||
.next | ||
.env.production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |