Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Clement-Muth/pcomparator into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement-Muth committed Oct 24, 2024
2 parents e3eccd6 + 30b336d commit 51b3e79
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
Binary file not shown.
Binary file not shown.
27 changes: 27 additions & 0 deletions src/applications/Authentication/Api/signup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use server";

import z from "zod";
import { db } from "~/libraries/kysely/db";

const ParamsSchema = z.object({
email: z.string(),
name: z.string(),
image: z.string()
});

export const signup = async (params: z.infer<typeof ParamsSchema>) => {
try {
const paramsPayload = ParamsSchema.parse(params);

const isUserAlreadyExists = await db.selectFrom("users").selectAll().executeTakeFirst();

if (!isUserAlreadyExists)
return await db
.insertInto("users")
.values({ email: paramsPayload.email, name: paramsPayload.name, image: paramsPayload.image })
.executeTakeFirstOrThrow();
else throw new Error("User already exists", { cause: "USER_ALREADY_EXISTS" });
} catch (err) {
console.error(err);
}
};
4 changes: 4 additions & 0 deletions src/libraries/kysely/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createKysely } from "@vercel/postgres-kysely";
import type { DB } from "~/types/db";

export const db = createKysely<DB>();
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9514,9 +9514,9 @@ __metadata:
linkType: hard

"electron-to-chromium@npm:^1.5.41":
version: 1.5.43
resolution: "electron-to-chromium@npm:1.5.43"
checksum: 5f8ed71e6461047efc7bf8728f1cd4cb82b9375f7db3eb29bf1014680797fec7591b2be5b483092e0cbd6d9b1cb90cd7c3375e13bce8136a0e0cb0a3f4690f2d
version: 1.5.45
resolution: "electron-to-chromium@npm:1.5.45"
checksum: f2e1ad7867125501d41f763e129d130bd563efebab65f5ca88a81407e834ff81d4e1e19355714d1e7f82a4662d3531fc23a0e9e9cdfb7b9ead0eb52ddcfa4b3e
languageName: node
linkType: hard

Expand Down

0 comments on commit 51b3e79

Please sign in to comment.