Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Make apis mostly private
Browse files Browse the repository at this point in the history
Signed-off-by: Audrow Nash <[email protected]>
  • Loading branch information
paudrow committed Nov 21, 2022
1 parent 742daa6 commit bc61f31
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
8 changes: 1 addition & 7 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ import { type NextPage } from "next";
import Head from "next/head";
import { signIn, signOut, useSession } from "next-auth/react";

import { trpc } from "../utils/trpc";

const Home: NextPage = () => {

const { data: sessionData } = useSession();

const { data: secretMessage } = trpc.auth.getSecretMessage.useQuery(
undefined, // no input
{ enabled: sessionData?.user !== undefined }
);
return (
<>
<Head>
Expand All @@ -26,7 +21,6 @@ const Home: NextPage = () => {
{sessionData && (
<span>Logged in as {sessionData.user?.name}</span>
)}
{secretMessage && <span> - {secretMessage}</span>}
</p>
<button
className="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
Expand Down
5 changes: 1 addition & 4 deletions src/server/trpc/router/auth.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { router, publicProcedure, protectedProcedure } from "../trpc";
import { router, publicProcedure } from "../trpc";

export const authRouter = router({
getSession: publicProcedure.query(({ ctx }) => {
return ctx.session;
}),
getSecretMessage: protectedProcedure.query(() => {
return "you can now see this secret message!";
}),
});
14 changes: 7 additions & 7 deletions src/server/trpc/router/plant.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { z } from "zod";
import dayjs from "dayjs";

import { router, publicProcedure } from "../trpc";
import { router, publicProcedure, protectedProcedure } from "../trpc";

export const plantsRouter = router({
getAll: publicProcedure.query(({ ctx }) => {
getAll: protectedProcedure.query(({ ctx }) => {
return ctx.prisma.plant.findMany({
where: {
userId: ctx.session?.user?.id,
},
});
}),
byId: publicProcedure
byId: protectedProcedure
.input(z.object({ id: z.string() }))
.query(({ ctx, input }) => {
return ctx.prisma.plant.findUnique({
Expand All @@ -20,7 +20,7 @@ export const plantsRouter = router({
},
});
}),
getIds: publicProcedure
getIds: protectedProcedure
.input(z.object({ userId: z.string() }))
.query(async ({ ctx, input: { userId } }) => {
const data = await ctx.prisma.plant.findMany({
Expand All @@ -33,7 +33,7 @@ export const plantsRouter = router({
});
return data.map((d) => d.id);
}),
create: publicProcedure
create: protectedProcedure
.input(
z.object({
name: z.string(),
Expand All @@ -52,7 +52,7 @@ export const plantsRouter = router({
},
});
}),
getNextTask: publicProcedure
getNextTask: protectedProcedure
.input(z.object({ plantId: z.string() }))
.query(async ({ ctx, input: { plantId } }) => {
const plant = await ctx.prisma.plant.findUnique({
Expand Down Expand Up @@ -105,7 +105,7 @@ export const plantsRouter = router({
},
});
}),
delete: publicProcedure
delete: protectedProcedure
.input(
z.object({
id: z.string(),
Expand Down
14 changes: 7 additions & 7 deletions src/server/trpc/router/taskRecord.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { z } from "zod";

import { router, publicProcedure } from "../trpc";
import { router, protectedProcedure } from "../trpc";
import { TaskType } from "../../../types/TaskType";

export const taskRecordsRouter = router({
getAll: publicProcedure.query(({ ctx }) => {
getAll: protectedProcedure.query(({ ctx }) => {
return ctx.prisma.taskRecord.findMany({
where: {
userId: ctx.session?.user?.id,
},
});
}),
byId: publicProcedure
byId: protectedProcedure
.input(z.object({ id: z.string() }))
.query(({ ctx, input }) => {
return ctx.prisma.taskRecord.findUnique({
Expand All @@ -20,7 +20,7 @@ export const taskRecordsRouter = router({
},
});
}),
getIds: publicProcedure
getIds: protectedProcedure
.input(z.object({ userId: z.string() }))
.query(async ({ ctx, input: { userId } }) => {
const data = await ctx.prisma.taskRecord.findMany({
Expand All @@ -33,7 +33,7 @@ export const taskRecordsRouter = router({
});
return data.map((d) => d.id);
}),
getForPlant: publicProcedure
getForPlant: protectedProcedure
.input(z.object({ plantId: z.string() }))
.query(async ({ ctx, input: { plantId } }) => {
return await ctx.prisma.taskRecord.findMany({
Expand All @@ -46,7 +46,7 @@ export const taskRecordsRouter = router({
});
}),

create: publicProcedure
create: protectedProcedure
.input(
z.object({
type: TaskType,
Expand Down Expand Up @@ -75,7 +75,7 @@ export const taskRecordsRouter = router({
},
});
}),
delete: publicProcedure
delete: protectedProcedure
.input(
z.object({
id: z.string(),
Expand Down

1 comment on commit bc61f31

@vercel
Copy link

@vercel vercel bot commented on bc61f31 Nov 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

plant-journal – ./

plant-journal-paudrow.vercel.app
maudrow-plant-journal.vercel.app
plant-journal-git-main-paudrow.vercel.app

Please sign in to comment.