mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-30 01:06:22 +02:00
♻️ Create backend package (#643)
This commit is contained in:
parent
7fc08c6736
commit
05fe2edaea
68 changed files with 476 additions and 391 deletions
27
packages/backend/trpc/routers/whoami.ts
Normal file
27
packages/backend/trpc/routers/whoami.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { prisma } from "@rallly/database";
|
||||
|
||||
import { publicProcedure, router } from "../trpc";
|
||||
import { UserSession } from "../types";
|
||||
|
||||
export const whoami = router({
|
||||
get: publicProcedure.query(async ({ ctx }): Promise<UserSession> => {
|
||||
if (ctx.user.isGuest) {
|
||||
return { isGuest: true, id: ctx.user.id };
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
select: { id: true, name: true, email: true },
|
||||
where: { id: ctx.user.id },
|
||||
});
|
||||
|
||||
if (user === null) {
|
||||
ctx.session.destroy();
|
||||
throw new Error("User not found");
|
||||
}
|
||||
|
||||
return { isGuest: false, ...user };
|
||||
}),
|
||||
destroy: publicProcedure.mutation(async ({ ctx }) => {
|
||||
ctx.session.destroy();
|
||||
}),
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue