added a primitive dit_info page (#268)

This commit is contained in:
pronom8
2025-04-10 15:36:51 +03:00
committed by GitHub
parent b72a2152b6
commit 6cfe6e6782
4 changed files with 84 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
import { checkSession } from "@/backend/auth/session";
export const dynamic = "force-dynamic"; // Ensures it's server-executed always
export async function GET() {
try {
const user = await checkSession();
if (!user) {
return new Response("Unauthorized", { status: 401 });
}
return Response.json({ user });
} catch (err) {
return new Response("Internal Server Error", { status: 500 });
}
}
+16
View File
@@ -0,0 +1,16 @@
"use client";
import "../auth/auth.css";
import { useIsLoggedIn } from "@/context/user.context";
export default function AuthLayout({ children }) {
const userLoggedIn = useIsLoggedIn();
if (userLoggedIn == true) {
console.log(userLoggedIn);
return (
<div className="auth-container">
<div className="auth-box">{children}</div>
</div>
);
}
}
+48
View File
@@ -0,0 +1,48 @@
"use client";
import { useState, useEffect } from "react";
import { useRouter } from "next/navigation";
import styles from "../page.module.css";
import { Container } from "@/components/ui/layout/container";
import { LinkButton } from "@/components/ui/linkbutton";
import { Grid } from "@radix-ui/themes";
export default function EditInfo() {
const [user, setUser] = useState(null);
const router = useRouter();
useEffect(() => {
const getUser = async () => {
const res = await fetch("/api/edit_info");
if (res.status === 401) {
router.replace("/auth/login");
return;
}
const data = await res.json();
setUser(data.user);
};
getUser();
}, [router]);
console.log(user);
if (!user) {
return <div className={styles.loader}>Loading...</div>;
}
return (
<Container>
<h1 className={styles.header}>Deine Profile </h1>
<h4>Benutzernam: {user.username}</h4>
<LinkButton href="/edit/password">Change Password</LinkButton>
<h4>Deine Email: {user.email}</h4>
<LinkButton href="/edit/email">Change email</LinkButton>
<Grid columns="2" gap="4"></Grid>
</Container>
);
}
@@ -61,6 +61,9 @@ function StudentSideBar() {
>
Vokabeln
</Link>
<Link className={styles.sidebarLink} href="/edit_info">
Profil
</Link>
</>
);
}