import { createFileRoute, redirect } from "@tanstack/react-router";
import { authClient } from "../../../../lib/authClient";
import ChangePassword from "../-components/ChangePassword";

export const Route = createFileRoute("/_app/(auth)/user/profile")({
	beforeLoad: async () => {
		const result = await authClient.getSession({
			query: { disableCookieCache: true }, // force DB/Server lookup
		});

		//console.log("session check:", result.data);

		if (!result.data) {
			throw redirect({
				to: "/login",
				search: {
					redirect: location.pathname + location.search,
				},
			});
		}
	},
	component: RouteComponent,
});

function RouteComponent() {
	//const { session } = useAuth();

	return (
		<div className="m-2">
			<div>
				{/* <span>Things you can change</span>
				<ol>
					<li>Display name: {session?.user.displayUsername}</li>
					<li>Name: {session?.user.name}</li>
					<li>Image: To be added</li>
					<li></li>
				</ol> */}
			</div>
			<ChangePassword />
		</div>
	);
}
