Skip to content

Commit edbc237

Browse files
Improve user teams access check for team members retrieval (e2b-dev#31)
2 parents 81d1957 + 72a44c1 commit edbc237

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/server/team/get-team-members.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { authActionClient } from '@/lib/clients/action'
88
import { returnServerError } from '@/lib/utils/action'
99
import { logError } from '@/lib/clients/logger'
1010
import { ERROR_CODES } from '@/configs/logs'
11+
import { checkUserTeamAuthorization } from '@/lib/utils/server'
1112

1213
const GetTeamMembersSchema = z.object({
1314
teamId: z.string().uuid(),
@@ -20,19 +21,6 @@ export const getTeamMembers = authActionClient
2021
const { teamId } = parsedInput
2122
const { user } = ctx
2223

23-
const { error: userTeamsRelationError } = await supabaseAdmin
24-
.from('users_teams')
25-
.select('*')
26-
.eq('user_id', user.id)
27-
.eq('team_id', teamId)
28-
.single()
29-
30-
if (userTeamsRelationError) {
31-
logError(ERROR_CODES.SUPABASE, userTeamsRelationError)
32-
33-
return returnServerError('User is not authorized to get team members')
34-
}
35-
3624
const { data, error } = await supabaseAdmin
3725
.from('users_teams')
3826
.select('*')
@@ -42,6 +30,13 @@ export const getTeamMembers = authActionClient
4230
throw error
4331
}
4432

33+
const accessGranted =
34+
data.findIndex((userTeam) => userTeam.user_id === user.id) !== -1
35+
36+
if (!accessGranted) {
37+
return returnServerError('User is not authorized to get team members')
38+
}
39+
4540
if (!data) {
4641
return []
4742
}

0 commit comments

Comments
 (0)