fix for overwriting email signup user

This commit is contained in:
austinkelsay 2024-10-06 16:21:29 -05:00
parent 2b3ff6285a
commit b2bee7b97d
2 changed files with 16 additions and 1 deletions

View File

@ -132,6 +132,21 @@ export const addCoursePurchaseToUser = async (userId, purchaseData) => {
};
export const createUser = async (data) => {
// Check if a user with the given email already exists
let existingUser = null;
// todo: special condition for email login, should be handled before getting here
if (data?.email) {
existingUser = await prisma.user.findUnique({
where: { email: data?.email },
});
}
if (existingUser) {
// If user exists, return the existing user
return existingUser;
}
// If user does not exist, create a new user
return await prisma.user.create({
data: {
...data,

View File

@ -10,7 +10,7 @@ const useCheckCourseProgress = () => {
if (!session?.user) return;
const userId = session.user.id;
const userCourses = session.user.userCourses;
const userCourses = session.user?.userCourses || [];
for (const userCourse of userCourses) {
const courseId = userCourse.courseId;