Skip to content

Commit f49c0b2

Browse files
authored
Merge pull request #3 from Codeunia/fix/auth
feat(auth): improve sign-in flow with error handling and success response
2 parents b317a77 + 58c7cbf commit f49c0b2

5 files changed

Lines changed: 59 additions & 6 deletions

File tree

app/(Root)/page.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
// import {Image} from "next/image"
21
import Link from "next/link";
32
import Image from "next/image";
43

54
import React from 'react'
65
import {Button} from '@/components/ui/button'
6+
import InterviewCard from "@/components/interviewCard";
7+
import { Interview } from "@/types";
78
// import { Link } from 'lucide-react'
89

910

1011

1112
const page = () => {
13+
const userInterviews: Interview[] = [];
14+
const allInterview: Interview[] = [];
15+
const user = { id: "1" };
16+
const hasPastInterviews = userInterviews.length > 0;
17+
const hasUpcomingInterviews = allInterview.length > 0;
1218
return (
1319
<>
1420
<section className="card-cta">
@@ -37,7 +43,7 @@ const page = () => {
3743

3844
<div className="interviews-section">
3945
{hasPastInterviews ? (
40-
userInterviews?.map((interview) => (
46+
userInterviews?.map((interview: Interview) => (
4147
<InterviewCard
4248
key={interview.id}
4349
userId={user?.id}
@@ -59,7 +65,7 @@ const page = () => {
5965

6066
<div className="interviews-section">
6167
{hasUpcomingInterviews ? (
62-
allInterview?.map((interview) => (
68+
allInterview?.map((interview: Interview) => (
6369
<InterviewCard
6470
key={interview.id}
6571
userId={user?.id}

components/AuthForm.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,16 @@ const AuthForm = ({ type }: { type: FormType }) => {
8282
return;
8383
}
8484

85-
await signIn({
85+
const result = await signIn({
8686
email,
8787
idToken,
8888
});
8989

90+
if (!result.success) {
91+
toast.error(result.message);
92+
return;
93+
}
94+
9095
toast.success("Signed in successfully.");
9196
router.push("/");
9297
}

components/interviewCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Button } from "./ui/button";
66
import DisplayTechIcons from "./DisplayTechIcons";
77

88
import { cn, getRandomInterviewCover } from "@/lib/utils";
9-
import { getFeedbackByInterviewId } from "@lib/actions/general.action";
9+
import { getFeedbackByInterviewId } from "@/lib/actions/general.action";
1010
import { InterviewCardProps } from "@/types";
1111
// @/lib/actions/general.action
1212

lib/actions/auth.action.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,13 @@ export async function signIn(params: SignInParams) {
8383
};
8484

8585
await setSessionCookie(idToken);
86+
87+
return {
88+
success: true,
89+
};
8690
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8791
} catch (error: any) {
88-
console.log("");
92+
console.log(error);
8993

9094
return {
9195
success: false,

lib/actions/general.action.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"use server";
2+
3+
import { db } from "@/firebase/admin";
4+
import { Feedback, GetFeedbackByInterviewIdParams } from "@/types";
5+
6+
export async function getFeedbackByInterviewId(
7+
params: GetFeedbackByInterviewIdParams
8+
): Promise<Feedback | null> {
9+
try {
10+
const { userId, interviewId } = params;
11+
12+
const feedbackRef = await db
13+
.collection("users")
14+
.doc(userId)
15+
.collection("interviews")
16+
.doc(interviewId)
17+
.collection("feedbacks")
18+
.get();
19+
20+
if (feedbackRef.empty) return null;
21+
22+
const feedback = feedbackRef.docs[0].data();
23+
24+
return {
25+
id: feedbackRef.docs[0].id,
26+
interviewId: feedback.interviewId,
27+
totalScore: feedback.totalScore,
28+
categoryScores: feedback.categoryScores,
29+
strengths: feedback.strengths,
30+
areasForImprovement: feedback.areasForImprovement,
31+
finalAssessment: feedback.finalAssessment,
32+
createdAt: feedback.createdAt.toDate(),
33+
};
34+
} catch (error) {
35+
console.log(error);
36+
return null;
37+
}
38+
}

0 commit comments

Comments
 (0)