-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from grant-baer/image-saving
Image saving
- Loading branch information
Showing
5 changed files
with
97 additions
and
73 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
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
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
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
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,33 +1,38 @@ | ||
import Link from "next/link"; | ||
import { isAuthenticated } from "./auth"; // Make sure to use the correct path | ||
import Cookie from "js-cookie"; | ||
import React, { useEffect, useState } from "react"; | ||
import Image from "next/image"; | ||
import axios from "axios"; | ||
|
||
export default function Portfolio() { | ||
const [portfolio, setPortfolio] = useState(null); | ||
|
||
useEffect(() => { | ||
async function fetch_portfolio() { | ||
await axios.get("http://localhost:5000/fetch_portfolio", | ||
{ | ||
headers: { | ||
"Authorization": `Bearer ${Cookie.get("token")}` | ||
} | ||
}).then(response => { | ||
setPortfolio(response.data); | ||
}).catch((error) => console.error("Error: ", error)); | ||
} | ||
fetch_portfolio(); | ||
}, []); | ||
|
||
return ( | ||
<div className="p-6"> | ||
<h1 className="text-2xl mb-4">Portfolio</h1> | ||
<div className="grid grid-cols-3 gap-4"> | ||
{/* You can map through your portfolio images/items here */} | ||
{portfolio && portfolio.map((image) => | ||
<Image src={"data:image/png;base64, " + image.data} | ||
loader={() => image.url} | ||
height={500} | ||
width={500} | ||
/>)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export async function getServerSideProps(context) { | ||
const { req } = context; | ||
const token = req.cookies["token"]; // Replace "your_cookie_name" with your actual cookie name | ||
|
||
if (!isAuthenticated(token)) { | ||
// If the user is not authenticated, redirect them to the login page | ||
return { | ||
redirect: { | ||
destination: "/login", | ||
permanent: false, | ||
}, | ||
}; | ||
} | ||
|
||
// If the user is authenticated, render the Portfolio page | ||
return { | ||
props: {}, // Will be passed to the page component as props | ||
}; | ||
} |