Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
owens1127 committed Nov 3, 2024
1 parent 193d73d commit b9cfaba
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 38 deletions.
22 changes: 11 additions & 11 deletions packages/db/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function main() {
update: {
sessions: {
update: {
where: { id: "23" },
where: { sessionId: "23" },
data: {
expiresAt: new Date(
new Date().setFullYear(new Date().getFullYear() + 10),
Expand All @@ -20,15 +20,15 @@ async function main() {
},
},
create: {
id: "7",
userId: "7",
email: "alice@prisma.io",
firstName: "Alice",
lastName: "Smith",
role: "MEDIA_MAKER",
hashedPassword: await hashPassword("alicePassword"),
sessions: {
create: {
id: "23",
sessionId: "23",
expiresAt: new Date(
new Date().setFullYear(new Date().getFullYear() + 10),
),
Expand All @@ -44,15 +44,15 @@ async function main() {
sessions: {
updateMany: [
{
where: { id: "12" },
where: { sessionId: "12" },
data: {
expiresAt: new Date(
new Date().setFullYear(new Date().getFullYear() - 1),
),
},
},
{
where: { id: "45" },
where: { sessionId: "45" },
data: {
expiresAt: new Date(
new Date().setFullYear(new Date().getFullYear() + 10),
Expand All @@ -63,7 +63,7 @@ async function main() {
},
},
create: {
id: "9",
userId: "9",
email: "bob@gmail.com",
firstName: "Bob",
lastName: "Jones",
Expand All @@ -73,13 +73,13 @@ async function main() {
createMany: {
data: [
{
id: "12",
sessionId: "12",
expiresAt: new Date(
new Date().setFullYear(new Date().getFullYear() - 1),
),
},
{
id: "45",
sessionId: "45",
expiresAt: new Date(
new Date().setFullYear(new Date().getFullYear() + 10),
),
Expand All @@ -96,7 +96,7 @@ async function main() {
update: {
sessions: {
update: {
where: { id: "78" },
where: { sessionId: "78" },
data: {
expiresAt: new Date(
new Date().setFullYear(new Date().getFullYear() - 1),
Expand All @@ -106,15 +106,15 @@ async function main() {
},
},
create: {
id: "56",
userId: "56",
email: "eve@outlook.com",
firstName: "Eve",
lastName: "Brown",
role: "MEDIA_MAKER",
hashedPassword: await hashPassword("evePassword"),
sessions: {
create: {
id: "78",
sessionId: "78",
expiresAt: new Date(
new Date().setFullYear(new Date().getFullYear() - 1),
),
Expand Down
4 changes: 2 additions & 2 deletions packages/trpc/src/internal/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const authenticatedProcedureBuilder = baseProcedureBuilder.use(

const sessionOrNull = await ctx.prisma.session.findUnique({
where: {
id: sessionId.value,
sessionId: sessionId.value,
},
include: {
user: {
Expand Down Expand Up @@ -96,7 +96,7 @@ export const notAuthenticatedProcedureBuilder = baseProcedureBuilder.use(

const sessionOrNull = await ctx.prisma.session.findUnique({
where: {
id: sessionId.value,
sessionId: sessionId.value,
},
});

Expand Down
10 changes: 5 additions & 5 deletions packages/trpc/src/procedures/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const signUpProcedure = notAuthenticatedProcedureBuilder
});
}

setSessionCookie(session.id, session.expiresAt);
setSessionCookie(session.sessionId, session.expiresAt);

return {
message: `Successfully signed up and logged in as ${input.email}`,
Expand Down Expand Up @@ -107,14 +107,14 @@ export const signInProcedure = notAuthenticatedProcedureBuilder
data: {
user: {
connect: {
id: user.id,
userId: user.userId,
},
},
expiresAt: getNewSessionExpirationDate(),
},
});

setSessionCookie(session.id, session.expiresAt);
setSessionCookie(session.sessionId, session.expiresAt);

return {
message: `Successfully logged in as ${input.email}`,
Expand All @@ -125,7 +125,7 @@ export const signOutProcedure = authenticatedProcedureBuilder.mutation(
async ({ ctx }) => {
await ctx.prisma.session.delete({
where: {
id: ctx.session.id,
sessionId: ctx.session.sessionId,
},
});

Expand All @@ -141,7 +141,7 @@ export const deleteAccountProcedure = authenticatedProcedureBuilder.mutation(
async ({ ctx }) => {
await ctx.prisma.user.delete({
where: {
id: ctx.session.userId,
userId: ctx.session.userId,
},
});

Expand Down
9 changes: 3 additions & 6 deletions tests/api/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ describe("auth", () => {
const createAccount = async () =>
prisma.user.upsert({
create: {
id: "testId124389124",
firstName: "Damian",
lastName: "Smith",
role: "MEDIA_MAKER",
email: "damian@gmail.com",
hashedPassword: await hashPassword("password123"),
},
update: {
id: "testId124389124",
email: "damian@gmail.com",
hashedPassword: await hashPassword("password123"),
},
Expand All @@ -43,15 +41,14 @@ describe("auth", () => {
user: {
connectOrCreate: {
create: {
id: "testId124389124",
firstName: "Damian",
lastName: "Smith",
role: "MEDIA_MAKER",
email: "damian@gmail.com",
hashedPassword: await hashPassword("password123"),
},
where: {
id: "testId124389124",
email: "damian@gmail.com",
},
},
},
Expand Down Expand Up @@ -151,7 +148,7 @@ describe("auth", () => {

test("auth/signOut", async () => {
const session = await createSession();
mockCookies.set("sessionId", session.id);
mockCookies.set("sessionId", session.sessionId);

const res = await $trpcCaller.signOut();

Expand All @@ -163,7 +160,7 @@ describe("auth", () => {

test("auth/deleteAccount", async () => {
const session = await createSession();
mockCookies.set("sessionId", session.id);
mockCookies.set("sessionId", session.sessionId);

const deleteAccountResponse = await $trpcCaller.deleteAccount();

Expand Down
18 changes: 9 additions & 9 deletions tests/api/get-authenticated-user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ beforeAll(async () => {
},
});
await prisma.session.upsert({
where: { id: "500" },
where: { sessionId: "500" },
update: {
expiresAt: new Date(
new Date().setFullYear(new Date().getFullYear() + 10),
),
},
create: {
userId: person1.id,
id: "500",
userId: person1.userId,
sessionId: "500",
expiresAt: new Date(
new Date().setFullYear(new Date().getFullYear() + 10),
),
Expand All @@ -46,26 +46,26 @@ beforeAll(async () => {
},
});
await prisma.session.upsert({
where: { id: "501" },
where: { sessionId: "501" },
update: {
expiresAt: new Date(new Date().setFullYear(new Date().getFullYear() - 1)),
},
create: {
userId: person2.id,
id: "501",
userId: person2.userId,
sessionId: "501",
expiresAt: new Date(new Date().setFullYear(new Date().getFullYear() - 1)),
},
});
await prisma.session.upsert({
where: { id: "502" },
where: { sessionId: "502" },
update: {
expiresAt: new Date(
new Date().setFullYear(new Date().getFullYear() + 10),
),
},
create: {
userId: person2.id,
id: "502",
userId: person2.userId,
sessionId: "502",
expiresAt: new Date(
new Date().setFullYear(new Date().getFullYear() + 10),
),
Expand Down
10 changes: 5 additions & 5 deletions tests/api/trpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe("middleware", () => {
beforeAll(async () => {
await prisma.user.create({
data: {
id: "middleware-test-user",
userId: "middleware-test-user",
email: "test@testing.com",
firstName: "test",
lastName: "user",
Expand All @@ -42,19 +42,19 @@ describe("middleware", () => {
createMany: {
data: [
{
id: "middleware-test-session",
sessionId: "middleware-test-session",
expiresAt: new Date(Date.now() + 200_000),
},
{
id: "middleware-test-session-expired",
sessionId: "middleware-test-session-expired",
expiresAt: new Date(Date.now() - 200_000),
},
],
},
},
},
select: {
id: true,
userId: true,
sessions: true,
},
});
Expand All @@ -69,7 +69,7 @@ describe("middleware", () => {
afterAll(async () => {
await prisma.user.delete({
where: {
id: "middleware-test-user",
userId: "middleware-test-user",
},
});
});
Expand Down

0 comments on commit b9cfaba

Please sign in to comment.