File tree 3 files changed +27
-1
lines changed
3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,11 @@ export default function CreateEventTypeButton(props: Props) {
84
84
const message = `${ err . statusCode } : ${ err . message } ` ;
85
85
showToast ( message , "error" ) ;
86
86
}
87
+
88
+ if ( err . data ?. code === "UNAUTHORIZED" ) {
89
+ const message = `${ err . data . code } : You are not able to create this event` ;
90
+ showToast ( message , "error" ) ;
91
+ }
87
92
} ,
88
93
} ) ;
89
94
Original file line number Diff line number Diff line change @@ -137,6 +137,11 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
137
137
const message = `${ err . statusCode } : ${ err . message } ` ;
138
138
showToast ( message , "error" ) ;
139
139
}
140
+
141
+ if ( err . data ?. code === "UNAUTHORIZED" ) {
142
+ const message = `${ err . data . code } : You are not able to update this event` ;
143
+ showToast ( message , "error" ) ;
144
+ }
140
145
} ,
141
146
} ) ;
142
147
Original file line number Diff line number Diff line change @@ -108,16 +108,32 @@ export const eventTypesRouter = createProtectedRouter()
108
108
input : createEventTypeInput ,
109
109
async resolve ( { ctx, input } ) {
110
110
const { schedulingType, teamId, ...rest } = input ;
111
+
112
+ const userId = ctx . user . id ;
113
+
111
114
const data : Prisma . EventTypeCreateInput = {
112
115
...rest ,
113
116
users : {
114
117
connect : {
115
- id : ctx . user . id ,
118
+ id : userId ,
116
119
} ,
117
120
} ,
118
121
} ;
119
122
120
123
if ( teamId && schedulingType ) {
124
+ const hasMembership = await ctx . prisma . membership . findFirst ( {
125
+ where : {
126
+ userId,
127
+ teamId : teamId ,
128
+ accepted : true ,
129
+ } ,
130
+ } ) ;
131
+
132
+ if ( ! hasMembership ) {
133
+ console . warn ( `User ${ userId } does not have permission to create this new event type` ) ;
134
+ throw new TRPCError ( { code : "UNAUTHORIZED" } ) ;
135
+ }
136
+
121
137
data . team = {
122
138
connect : {
123
139
id : teamId ,
You can’t perform that action at this time.
0 commit comments