From d0b7ff18f6ef8c86b0b4a6720d3b995a7c001009 Mon Sep 17 00:00:00 2001 From: VineeTagarwaL-code Date: Sun, 29 Sep 2024 22:56:47 +0530 Subject: [PATCH] fix: added user in 0auth login --- next.config.js | 8 +++-- prisma/seed.ts | 2 +- src/actions/auth.actions.ts | 64 ++++++++++++++++++++---------------- src/actions/upload-to-cdn.ts | 1 - src/app/create/page.tsx | 1 + src/components/job-card.tsx | 2 +- src/components/job-form.tsx | 24 -------------- src/layouts/header.tsx | 10 +++++- src/lib/authOptions.ts | 5 ++- 9 files changed, 55 insertions(+), 62 deletions(-) diff --git a/next.config.js b/next.config.js index ce43b208..a7a7256c 100644 --- a/next.config.js +++ b/next.config.js @@ -23,13 +23,17 @@ const nextConfig = { }, { protocol: 'https', - hostname: 'wwww.example.com', + hostname: 'lh3.googleusercontent.com', + // Change this to your CDN domain }, - { protocol: 'https', hostname: 'aakash2330.b-cdn.net', }, + { + protocol: 'https', + hostname: 'wwww.example.com', + }, ], }, }; diff --git a/prisma/seed.ts b/prisma/seed.ts index 214ae561..e17c7580 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -333,7 +333,7 @@ async function seedJobs() { currency: j.currency, application: j.application, city: faker.location.city(), - address: faker.location.streetAddress(), + address: faker.location.city(), hasExperiencerange: j.hasExperiencerange, minExperience: j.minExperience, maxExperience: j.maxExperience, diff --git a/src/actions/auth.actions.ts b/src/actions/auth.actions.ts index b582dfaa..9db6d30b 100644 --- a/src/actions/auth.actions.ts +++ b/src/actions/auth.actions.ts @@ -39,40 +39,46 @@ export const signUp = withServerActionAsyncCatcher< ); try { - await prisma.$transaction(async (txn) => { - const user = await txn.user.create({ - data: { ...data, password: hashedPassword }, - }); - - const verificationToken = await txn.verificationToken.create({ - data: { - identifier: user.id, - token: uuidv4(), - type: 'EMAIL_VERIFICATION', - }, - }); - - const confirmationLink = `${process.env.NEXTAUTH_URL}${APP_PATHS.VERIFY_EMAIL}/${verificationToken.token}`; - await sendConfirmationEmail( - data.email, - confirmationLink, - 'EMAIL_VERIFICATION' - ); - - cookies().set(PENDING_EMAIL_VERIFICATION_USER_ID, user.id, { - maxAge: 5 * 60, // 5 minutes - httpOnly: true, - secure: process.env.NODE_ENV === 'production', - }); - - return user; - }); + await prisma.$transaction( + async (txn) => { + const user = await txn.user.create({ + data: { ...data, password: hashedPassword }, + }); + + const verificationToken = await txn.verificationToken.create({ + data: { + identifier: user.id, + token: uuidv4(), + type: 'EMAIL_VERIFICATION', + }, + }); + + const confirmationLink = `${process.env.NEXTAUTH_URL}${APP_PATHS.VERIFY_EMAIL}/${verificationToken.token}`; + await sendConfirmationEmail( + data.email, + confirmationLink, + 'EMAIL_VERIFICATION' + ); + + cookies().set(PENDING_EMAIL_VERIFICATION_USER_ID, user.id, { + maxAge: 5 * 60, // 5 minutes + httpOnly: true, + secure: process.env.NODE_ENV === 'production', + }); + + return user; + }, + { + maxWait: 5000, + timeout: 20000, + } + ); return new SuccessResponse( 'User registered successfully. A verification link has been sent to your email.', 201 ).serialize(); - } catch { + } catch (_err) { throw new ErrorHandler( 'Registration Failed, please try again!', 'INTERNAL_SERVER_ERROR' diff --git a/src/actions/upload-to-cdn.ts b/src/actions/upload-to-cdn.ts index 935d0754..ca967570 100644 --- a/src/actions/upload-to-cdn.ts +++ b/src/actions/upload-to-cdn.ts @@ -26,7 +26,6 @@ export async function uploadFileAction(formData: FormData) { }, body: fileBuffer, }); - if (response.ok) { return { message: 'File uploaded successfully', diff --git a/src/app/create/page.tsx b/src/app/create/page.tsx index 428dad04..034eb1e6 100644 --- a/src/app/create/page.tsx +++ b/src/app/create/page.tsx @@ -10,6 +10,7 @@ const page = () => { 100xJobs is trusted by leading companies

+ ); diff --git a/src/components/job-card.tsx b/src/components/job-card.tsx index eae54e94..66e84908 100644 --- a/src/components/job-card.tsx +++ b/src/components/job-card.tsx @@ -31,7 +31,7 @@ export default function JobCard({ job }: { job: JobType }) {
- {job.type && job?.type.toUpperCase()} + {job.type && job?.type.toUpperCase().replace('_', ' ')}
diff --git a/src/components/job-form.tsx b/src/components/job-form.tsx index 426e9afb..7607c614 100644 --- a/src/components/job-form.tsx +++ b/src/components/job-form.tsx @@ -130,7 +130,6 @@ const PostJobForm = () => { try { data.companyLogo = (await submitImage(file)) ?? 'https://wwww.example.com'; - ``; const response = await createJob(data); if (!response.status) { @@ -513,29 +512,6 @@ const PostJobForm = () => {
- -
-

Payment

- - -
-

- "I'm a huge fan of remote work and 100xJobs is by far my - favorite job board." -

- 100xJobs -

Harkirat Singh

-

100xJobs.com

-
-
); diff --git a/src/layouts/header.tsx b/src/layouts/header.tsx index a973966f..cf3ecf53 100644 --- a/src/layouts/header.tsx +++ b/src/layouts/header.tsx @@ -117,9 +117,17 @@ const Header = () => { src={ session.data.user.image ? session.data.user.image - : '' + : 'hello' } /> + {/* {session.data.user.name} */} + {getNameInitials(session.data.user.name)} diff --git a/src/lib/authOptions.ts b/src/lib/authOptions.ts index e57d26ef..73285f8b 100644 --- a/src/lib/authOptions.ts +++ b/src/lib/authOptions.ts @@ -87,7 +87,6 @@ export const authOptions = { }, }); if (existingUser?.blockedByAdmin) return false; - if (!existingUser) { existingUser = await prisma.user.create({ data: { @@ -96,6 +95,7 @@ export const authOptions = { email: email as string, name: name as string, avatar, + isVerified: true, emailVerified: new Date(), }, }); @@ -122,11 +122,10 @@ export const authOptions = { }, }); if (!loggedInUser) return null; - token.id = loggedInUser.id; token.name = user.name; token.isVerified = user.isVerified; - token.role = user.role; + token.role = loggedInUser.role ? loggedInUser.role : user.role; } return token; },