From 58c7cbf7c28b27d1ca5659a42517b669bd4ad2f8 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 19 Aug 2025 23:11:47 +0530 Subject: [PATCH] feat(auth): improve sign-in flow with error handling and success response refactor(imports): update import paths to use @/ alias consistently --- app/(Root)/page.tsx | 12 ++++++++--- components/AuthForm.tsx | 7 ++++++- components/interviewCard.tsx | 2 +- lib/actions/auth.action.ts | 6 +++++- lib/actions/general.action.ts | 38 +++++++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 lib/actions/general.action.ts diff --git a/app/(Root)/page.tsx b/app/(Root)/page.tsx index ed5ad6d..7274fbb 100644 --- a/app/(Root)/page.tsx +++ b/app/(Root)/page.tsx @@ -1,14 +1,20 @@ -// import {Image} from "next/image" import Link from "next/link"; import Image from "next/image"; import React from 'react' import {Button} from '@/components/ui/button' +import InterviewCard from "@/components/interviewCard"; +import { Interview } from "@/types"; // import { Link } from 'lucide-react' const page = () => { + const userInterviews: Interview[] = []; + const allInterview: Interview[] = []; + const user = { id: "1" }; + const hasPastInterviews = userInterviews.length > 0; + const hasUpcomingInterviews = allInterview.length > 0; return ( <>
@@ -37,7 +43,7 @@ const page = () => {
{hasPastInterviews ? ( - userInterviews?.map((interview) => ( + userInterviews?.map((interview: Interview) => ( {
{hasUpcomingInterviews ? ( - allInterview?.map((interview) => ( + allInterview?.map((interview: Interview) => ( { return; } - await signIn({ + const result = await signIn({ email, idToken, }); + if (!result.success) { + toast.error(result.message); + return; + } + toast.success("Signed in successfully."); router.push("/"); } diff --git a/components/interviewCard.tsx b/components/interviewCard.tsx index 2c9c2dd..6cd9e07 100644 --- a/components/interviewCard.tsx +++ b/components/interviewCard.tsx @@ -6,7 +6,7 @@ import { Button } from "./ui/button"; import DisplayTechIcons from "./DisplayTechIcons"; import { cn, getRandomInterviewCover } from "@/lib/utils"; -import { getFeedbackByInterviewId } from "@lib/actions/general.action"; +import { getFeedbackByInterviewId } from "@/lib/actions/general.action"; import { InterviewCardProps } from "@/types"; // @/lib/actions/general.action diff --git a/lib/actions/auth.action.ts b/lib/actions/auth.action.ts index 620706c..484b54f 100644 --- a/lib/actions/auth.action.ts +++ b/lib/actions/auth.action.ts @@ -83,9 +83,13 @@ export async function signIn(params: SignInParams) { }; await setSessionCookie(idToken); + + return { + success: true, + }; // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { - console.log(""); + console.log(error); return { success: false, diff --git a/lib/actions/general.action.ts b/lib/actions/general.action.ts new file mode 100644 index 0000000..edb9080 --- /dev/null +++ b/lib/actions/general.action.ts @@ -0,0 +1,38 @@ +"use server"; + +import { db } from "@/firebase/admin"; +import { Feedback, GetFeedbackByInterviewIdParams } from "@/types"; + +export async function getFeedbackByInterviewId( + params: GetFeedbackByInterviewIdParams +): Promise { + try { + const { userId, interviewId } = params; + + const feedbackRef = await db + .collection("users") + .doc(userId) + .collection("interviews") + .doc(interviewId) + .collection("feedbacks") + .get(); + + if (feedbackRef.empty) return null; + + const feedback = feedbackRef.docs[0].data(); + + return { + id: feedbackRef.docs[0].id, + interviewId: feedback.interviewId, + totalScore: feedback.totalScore, + categoryScores: feedback.categoryScores, + strengths: feedback.strengths, + areasForImprovement: feedback.areasForImprovement, + finalAssessment: feedback.finalAssessment, + createdAt: feedback.createdAt.toDate(), + }; + } catch (error) { + console.log(error); + return null; + } +}