Skip to content

Commit

Permalink
fix: added user in 0auth login
Browse files Browse the repository at this point in the history
  • Loading branch information
VineeTagarwaL-code committed Sep 29, 2024
1 parent 4b3549a commit d0b7ff1
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 62 deletions.
8 changes: 6 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
},
};
Expand Down
2 changes: 1 addition & 1 deletion prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
64 changes: 35 additions & 29 deletions src/actions/auth.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion src/actions/upload-to-cdn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export async function uploadFileAction(formData: FormData) {
},
body: fileBuffer,
});

if (response.ok) {
return {
message: 'File uploaded successfully',
Expand Down
1 change: 1 addition & 0 deletions src/app/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const page = () => {
100xJobs is trusted by leading companies
</p>
</div>

<PostJobForm />
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/job-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function JobCard({ job }: { job: JobType }) {
</div>
<div className="flex items-center gap-4">
<div className="px-4 py-1 w-fit text-blue-500 bg-blue-500/20 rounded-lg flex items-center justify-center text-xs font-bold">
{job.type && job?.type.toUpperCase()}
{job.type && job?.type.toUpperCase().replace('_', ' ')}
</div>
<div className="flex items-center gap-2">
<MapPin size={16} />
Expand Down
24 changes: 0 additions & 24 deletions src/components/job-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ const PostJobForm = () => {
try {
data.companyLogo =
(await submitImage(file)) ?? 'https://wwww.example.com';
``;
const response = await createJob(data);

if (!response.status) {
Expand Down Expand Up @@ -513,29 +512,6 @@ const PostJobForm = () => {
</div>
</form>
</Form>

<div className="mb-2 bg-gray-900 w-full p-6 rounded-lg mx-auto text-gray-300">
<h2 className="text-lg font-semibold mb-4 text-gray-300">Payment</h2>
<Button className="w-full rounded-full mt-4">
Continue to Payment
</Button>

<div className="flex mt-4 gap-2 flex-col items-center">
<h1 className="text-center text-gray-400">
&quot;I&apos;m a huge fan of remote work and 100xJobs is by far my
favorite job board.&quot;
</h1>
<Image
src={'/main.png'}
alt="100xJobs"
width={40}
height={40}
className="rounded-full"
/>
<h1 className="text-gray-300">Harkirat Singh</h1>
<h1 className="text-sm text-gray-300">100xJobs.com</h1>
</div>
</div>
</div>
</div>
);
Expand Down
10 changes: 9 additions & 1 deletion src/layouts/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,17 @@ const Header = () => {
src={
session.data.user.image
? session.data.user.image
: ''
: 'hello'
}
/>
{/* <Image
src={session.data.user.image}
alt={session.data.user.name}
width={32}
height={32}
className="rounded-full"
/> */}

<AvatarFallback>
{getNameInitials(session.data.user.name)}
</AvatarFallback>
Expand Down
5 changes: 2 additions & 3 deletions src/lib/authOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export const authOptions = {
},
});
if (existingUser?.blockedByAdmin) return false;

if (!existingUser) {
existingUser = await prisma.user.create({
data: {
Expand All @@ -96,6 +95,7 @@ export const authOptions = {
email: email as string,
name: name as string,
avatar,
isVerified: true,
emailVerified: new Date(),
},
});
Expand All @@ -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;
},
Expand Down

0 comments on commit d0b7ff1

Please sign in to comment.