mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-06 18:31:00 +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) => {
|
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({
|
return await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
...data,
|
...data,
|
||||||
|
@ -10,7 +10,7 @@ const useCheckCourseProgress = () => {
|
|||||||
if (!session?.user) return;
|
if (!session?.user) return;
|
||||||
|
|
||||||
const userId = session.user.id;
|
const userId = session.user.id;
|
||||||
const userCourses = session.user.userCourses;
|
const userCourses = session.user?.userCourses || [];
|
||||||
|
|
||||||
for (const userCourse of userCourses) {
|
for (const userCourse of userCourses) {
|
||||||
const courseId = userCourse.courseId;
|
const courseId = userCourse.courseId;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user