Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in Clerk webhook: ensure user creation in Convex DB for email signups without first name #8

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions app/(root)/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import PodcastCard from "@/components/PodcastCard";
import ProfileCard from "@/components/ProfileCard";
import { api } from "@/convex/_generated/api";
import { ProfilePodcastProps } from "@/types";
import { useClerk } from "@clerk/nextjs";

const MyProfilePage = () => {

const { user } = useClerk();
const user = useQuery(api.users.getUser);

const podcastsData = useQuery(api.podcasts.getPodcastByAuthorId, {
authorId: user?.id!,
authorId: user?.clerkId!,
}) as ProfilePodcastProps;

if (!user || !podcastsData) return <LoaderSpinner />;
Expand All @@ -27,10 +26,10 @@ const MyProfilePage = () => {
</h1>
<div className="mt-6 flex flex-col gap-6 max-md:items-center md:flex-row">
<ProfileCard
profileId={user.id}
profileId={user.clerkId}
podcastData={podcastsData}
imageUrl={user?.imageUrl!}
userFirstName={user.firstName!}
userFirstName={user.name}
/>
</div>
<section className="mt-9 flex flex-col gap-5">
Expand Down
6 changes: 5 additions & 1 deletion components/RightSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ const RightSidebar = () => {
<Link href={`/profile/${user?.id}`} className="flex gap-3 pb-12">
<UserButton />
<div className="flex w-full items-center justify-between">
<h1 className="text-16 truncate font-semibold text-white-1">{user?.firstName} {user?.lastName}</h1>
<h1 className="text-16 truncate font-semibold text-white-1">
{ user?.firstName && user?.lastName ?
user?.firstName + " " + user?.lastName
: user?.emailAddresses[0].emailAddress.split("@")[0]}
</h1>
<Image
src="/icons/right-arrow.svg"
alt="arrow"
Expand Down
4 changes: 3 additions & 1 deletion convex/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const handleClerkWebhook = httpAction(async (ctx, request) => {
clerkId: event.data.id,
email: event.data.email_addresses[0].email_address,
imageUrl: event.data.image_url,
name: event.data.first_name!,
name: event.data.first_name
? event.data.first_name + " " + (event.data.last_name ?? "")
: event.data.email_addresses[0].email_address.split("@")[0],
});
break;
case "user.updated":
Expand Down
Loading