feat: Implement authentication checks for profile actions and user layout, and add presigned URL fetching for file viewing.

This commit is contained in:
pradeepkumar
2026-01-29 00:02:59 +05:30
parent 4ffd6305b1
commit b41bd8a3eb
9 changed files with 243 additions and 40 deletions

View File

@@ -2,6 +2,8 @@
import Image from 'next/image';
import Link from 'next/link';
import { useSession } from 'next-auth/react';
import { useRouter, usePathname } from 'next/navigation';
import { Tag } from './Tag';
interface ProfileCardProps {
@@ -33,6 +35,26 @@ export function ProfileCard({
messageHref,
requestsHref,
}: ProfileCardProps) {
const { data: session } = useSession();
const router = useRouter();
const pathname = usePathname();
// Handle action click - require login if not authenticated
const handleActionClick = (e: React.MouseEvent, targetHref?: string) => {
if (!session) {
e.preventDefault();
// Store the current page to redirect back after login
const returnUrl = encodeURIComponent(pathname);
router.push(`/login?callbackUrl=${returnUrl}`);
return;
}
// If logged in and has href, navigation will happen naturally via Link
if (!targetHref) {
e.preventDefault();
// Handle button click when logged in but no href specified
}
};
return (
<div className="bg-white rounded-[20px] p-4 lg:p-5">
{/* Name and Actions Row */}
@@ -99,6 +121,7 @@ export function ProfileCard({
{messageHref ? (
<Link
href={messageHref}
onClick={(e) => handleActionClick(e, messageHref)}
className="flex items-center gap-2 px-4 py-1.5 bg-[#e58625] text-[#00293d] text-sm font-normal rounded-[15px] border border-[#00293d]/10 hover:bg-[#d47720] transition-colors font-serif cursor-pointer"
>
<Image
@@ -111,6 +134,7 @@ export function ProfileCard({
</Link>
) : (
<button
onClick={(e) => handleActionClick(e)}
className="flex items-center gap-2 px-4 py-1.5 bg-[#e58625] text-[#00293d] text-sm font-normal rounded-[15px] border border-[#00293d]/10 hover:bg-[#d47720] transition-colors font-serif cursor-pointer"
>
<Image
@@ -125,6 +149,7 @@ export function ProfileCard({
{requestsHref ? (
<Link
href={requestsHref}
onClick={(e) => handleActionClick(e, requestsHref)}
className="flex items-center gap-2 px-4 py-1.5 bg-[#e58625] text-[#00293d] text-sm font-normal rounded-[15px] border border-[#00293d]/10 hover:bg-[#d47720] transition-colors font-serif cursor-pointer"
>
<Image
@@ -137,6 +162,7 @@ export function ProfileCard({
</Link>
) : (
<button
onClick={(e) => handleActionClick(e)}
className="flex items-center gap-2 px-4 py-1.5 bg-[#e58625] text-[#00293d] text-sm font-normal rounded-[15px] border border-[#00293d]/10 hover:bg-[#d47720] transition-colors font-serif cursor-pointer"
>
<Image