File tree Expand file tree Collapse file tree 3 files changed +28
-14
lines changed
Expand file tree Collapse file tree 3 files changed +28
-14
lines changed Original file line number Diff line number Diff line change 1- import { router , authProcedure } from '../trpc' ;
1+ import { router , authProcedure , demoAuthMiddleware } from '../trpc' ;
22import { z } from 'zod' ;
33import { prisma } from '../prisma' ;
44import { Prisma } from '@prisma/client' ;
@@ -203,7 +203,7 @@ export const noteRouter = router({
203203 }
204204 return await prisma . notes . updateMany ( { where : { id : { in : ids } } , data : update } )
205205 } ) ,
206- deleteMany : authProcedure
206+ deleteMany : authProcedure . use ( demoAuthMiddleware )
207207 . input ( z . object ( {
208208 ids : z . array ( z . number ( ) )
209209 } ) )
Original file line number Diff line number Diff line change 1- import { router , authProcedure } from '../trpc' ;
1+ import { router , authProcedure , demoAuthMiddleware } from '../trpc' ;
22import { z } from 'zod' ;
33import { prisma } from '../prisma' ;
44import { caller } from './_app' ;
@@ -51,7 +51,7 @@ export const tagRouter = router({
5151 const { id, icon } = input
5252 return await prisma . tag . update ( { where : { id } , data : { icon } } )
5353 } ) ,
54- deleteOnlyTag : authProcedure
54+ deleteOnlyTag : authProcedure . use ( demoAuthMiddleware )
5555 . input ( z . object ( {
5656 id : z . number ( )
5757 } ) )
@@ -67,7 +67,7 @@ export const tagRouter = router({
6767 await prisma . tag . delete ( { where : { id } } )
6868 return true
6969 } ) ,
70- deleteTagWithAllNote : authProcedure
70+ deleteTagWithAllNote : authProcedure . use ( demoAuthMiddleware )
7171 . input ( z . object ( {
7272 id : z . number ( )
7373 } ) )
Original file line number Diff line number Diff line change @@ -22,16 +22,30 @@ export const t = initTRPC.meta<OpenApiMeta>().context<Context>().create({
2222
2323export const router = t . router ;
2424export const publicProcedure = t . procedure ;
25- export const authProcedure = t . procedure . use ( async ( { ctx, next} ) => {
26- if ( ! ctx . ok ) {
27- throw new TRPCError ( {
28- code : "UNAUTHORIZED" ,
29- message : 'Unauthorized'
30- } )
31- }
32- return next ( {
33- ctx
25+ export const authProcedure = t . procedure . use ( async ( { ctx, next } ) => {
26+ if ( ! ctx . ok ) {
27+ throw new TRPCError ( {
28+ code : "UNAUTHORIZED" ,
29+ message : 'Unauthorized'
3430 } )
31+ }
32+ return next ( {
33+ ctx
34+ } )
3535} )
3636
37+
38+ export const demoAuthMiddleware = t . middleware ( async ( { ctx, next } ) => {
39+ if ( process . env . IS_DEMO ) {
40+ throw new TRPCError ( {
41+ code : "FORBIDDEN" ,
42+ message : 'The operation is rejected because this is a demo environment'
43+ } )
44+ }
45+ return next ( {
46+ ctx
47+ } ) ;
48+ } ) ;
49+
50+
3751export const mergeRouters = t . mergeRouters ;
You can’t perform that action at this time.
0 commit comments