Skip to content

Commit

Permalink
fix(template,stackoverflow): fix clerk user types
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaosen7 committed Jul 30, 2024
1 parent cfa46d3 commit f926faa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions apps/stackoverflow/src/libs/actions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import { prisma } from "@/prisma";
import { IUser, toast } from "@/shared";
import { auth, currentUser } from "@clerk/nextjs/server";

async function getClerkId() {
const clerkUser = await currentUser();
return clerkUser?.id;
}

export async function getCurrent() {
const { clerkUser: userId } = auth();
if (!userId) {
const clerkId = await getClerkId();
if (!clerkId) {
return null;
}

const user = await prisma.user.findUnique({
where: {
clerkId: userId,
clerkId,
},
});
return user;
Expand Down
4 changes: 2 additions & 2 deletions apps/template/src/libs/actions/user.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use server";

import { prisma } from "@/libs/prisma/client";
import { auth } from "@clerk/nextjs/server";
import { currentUser } from "@clerk/nextjs/server";

export async function createUserIfNeeded() {
try {
const { clerkUser: clerkId } = auth();
const clerkId = (await currentUser())?.id;

if (!clerkId) {
return;
Expand Down

0 comments on commit f926faa

Please sign in to comment.