Skip to content

Commit ad7f3d6

Browse files
authored
Create ask question (#10)
* Create ask-question form * Added shadcn form and label components * Added clerk webhook route * Created question model * Created user model * Created the tag model * Created connection to the database * Added shared types between actions * Added ask question form data validation * Created the question actions * Created the user actions * Created the ask-question page * Added get all questions from the db * Added api/webhook to public routes * Updated api/webhooks public route * Checking webhook * Checking event type * Fix user update action * Update author imgUrl src * Configure images with hostname * Get userId from auth * Fix avatar rounded className * Remove unnecessary console.log
1 parent 68043e9 commit ad7f3d6

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

app/(root)/ask-question/page.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { auth } from '@clerk/nextjs/server';
44
import { redirect } from 'next/navigation';
55

66
const AskQuestion = async () => {
7-
// const { userId } = await auth();
8-
9-
const userId = 'clerk12345';
7+
const { userId } = await auth();
108

119
if (!userId) redirect('/sign-in');
1210

components/cards/QuestionCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const QuestionCard = ({
4646
</div>
4747
<div className="flex-between mt-6 w-full flex-wrap gap-3">
4848
<Metric
49-
imgUrl="/assets/icons/avatar.svg"
49+
imgUrl={author.picture}
5050
alt={author.name}
5151
value={author.name}
5252
title={` • ${getTimeStamp(createdAt)}`}

components/shared/Metric.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const Metric = ({
2727
alt={alt}
2828
width={16}
2929
height={16}
30-
className={`object-contain ${href ? 'rounded-fill' : ''}`}
30+
className={`object-contain ${href ? 'rounded-full' : ''}`}
3131
/>
3232
<p className={`flex items-center gap-1 ${textStyles}`}>
3333
<span>{value}</span>

lib/actions/user.action.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ export async function createUser(params: CreateUserParams) {
3838
export async function updateUser(params: UpdateUserParams) {
3939
try {
4040
connectToDatabase();
41+
4142
const { clerkId, updateData, path } = params;
42-
await User.findByIdAndUpdate({ clerkId }, updateData, { new: true });
43+
await User.findOneAndUpdate({ clerkId }, updateData, { new: true });
4344

4445
revalidatePath(path);
4546
} catch (error) {

middleware.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server';
22

3-
const isPublicRoute = createRouteMatcher(['/sign-in(.*)', '/sign-up(.*)', '/']);
3+
const isPublicRoute = createRouteMatcher([
4+
'/sign-in(.*)',
5+
'/sign-up(.*)',
6+
'/',
7+
'/api/webhooks(.*)',
8+
'/api/chatgpt',
9+
'/question/:id',
10+
'/tags',
11+
'/tags/:id',
12+
'/community',
13+
'/jobs',
14+
]);
415

516
export default clerkMiddleware(async (auth, request) => {
617
if (!isPublicRoute(request)) {

next.config.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
import type { NextConfig } from "next";
1+
import type { NextConfig } from 'next';
22

33
const nextConfig: NextConfig = {
44
/* config options here */
5+
images: {
6+
remotePatterns: [
7+
{
8+
protocol: 'https',
9+
hostname: '*',
10+
},
11+
{
12+
protocol: 'http',
13+
hostname: '*',
14+
},
15+
],
16+
},
517
};
618

719
export default nextConfig;

0 commit comments

Comments
 (0)