mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-05-13 05:07:46 +00:00
fix: profile picture null causes crash
This commit is contained in:
parent
ed9a480385
commit
0ede4c7260
3 changed files with 10 additions and 6 deletions
|
|
@ -69,7 +69,13 @@ export default function Header() {
|
|||
data-tooltip="Your Profile"
|
||||
>
|
||||
<img
|
||||
src={$session.user.image.startsWith("/profile") ? `${import.meta.env.VITE_API_URL}${$session.user.image}` : $session.user.image}
|
||||
src={
|
||||
$session?.user?.image
|
||||
? $session.user.image.startsWith("/profile")
|
||||
? `${import.meta.env.VITE_API_URL}${$session.user.image}`
|
||||
: $session.user.image
|
||||
: "/guest.png"
|
||||
}
|
||||
onError={(e) => {
|
||||
e.currentTarget.onerror = null; // Prevent infinite loops
|
||||
e.currentTarget.src = "/guest.png";
|
||||
|
|
|
|||
|
|
@ -51,9 +51,7 @@ export default function ProfileLayout() {
|
|||
const joinDate = new Date(user.createdAt).toLocaleDateString("en-US", { month: "long", year: "numeric" });
|
||||
const metaTitle = `${user.name} - TomodachiShare`;
|
||||
const metaDescription = `View ${user.name}'s profile on TomodachiShare. Creator of ${user._count.miis} Miis. Member since ${joinDate}.`;
|
||||
const metaImage = user.image.startsWith("/profile")
|
||||
? `${import.meta.env.VITE_API_URL}${user.image}`
|
||||
: (user.image ?? `${import.meta.env.VITE_API_URL}/guest.png`);
|
||||
const metaImage = user.image ? (user.image.startsWith("/profile") ? `${import.meta.env.VITE_API_URL}${user.image}` : user.image) : "/guest.png";
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
|
@ -81,7 +79,7 @@ export default function ProfileLayout() {
|
|||
{/* Profile picture */}
|
||||
<Link to={`/profile/${user.id}`} className="size-28 aspect-square">
|
||||
<img
|
||||
src={user.image.startsWith("/profile") ? `${import.meta.env.VITE_API_URL}${user.image}` : user.image}
|
||||
src={user.image ? (user.image.startsWith("/profile") ? `${import.meta.env.VITE_API_URL}${user.image}` : user.image) : "/guest.png"}
|
||||
onError={(e) => {
|
||||
e.currentTarget.onerror = null; // Prevent infinite loops
|
||||
e.currentTarget.src = "/guest.png";
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ export default function ReportUserPage() {
|
|||
|
||||
<div className="bg-orange-100 rounded-xl border-2 border-orange-400 flex p-4 gap-4">
|
||||
<img
|
||||
src={user.image.startsWith("/profile") ? `${import.meta.env.VITE_API_URL}${user.image}` : user.image}
|
||||
src={user.image ? (user.image.startsWith("/profile") ? `${import.meta.env.VITE_API_URL}${user.image}` : user.image) : "/guest.png"}
|
||||
onError={(e) => {
|
||||
e.currentTarget.onerror = null; // Prevent infinite loops
|
||||
e.currentTarget.src = "/guest.png";
|
||||
|
|
|
|||
Loading…
Reference in a new issue