mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-04-19 19:01:19 +00:00
fix for overwriting email signup user
This commit is contained in:
parent
2b3ff6285a
commit
b2bee7b97d
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user