Skip to content

Commit

Permalink
fix(createCard): make sure user exists
Browse files Browse the repository at this point in the history
  • Loading branch information
flowergardn committed Dec 9, 2023
1 parent 8ed2326 commit 7aa64c7
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/server/api/routers/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ export const cardRouter = createTRPCRouter({
}),
)
.mutation(async ({ ctx, input }) => {
// Creates the user if it doesn't exist
// Could probably use clerk webhooks, but
// this is more of a solid approach.

const user = await ctx.db.user.findUnique({
where: {
id: ctx.userId,
},
});

if (!user) {
await ctx.db.user.create({
data: {
id: ctx.userId,
},
});
}

const card = await ctx.db.cards.create({
data: {
birthday: input.birthday,
Expand Down

0 comments on commit 7aa64c7

Please sign in to comment.