Skip to content

Commit

Permalink
Check if organization is deleted in middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Peyton-McKee committed Jan 9, 2025
1 parent add39e6 commit 96c026f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/backend/src/utils/auth.utils.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import jwt from 'jsonwebtoken';
import { Request, Response, NextFunction } from 'express';
import { JwtPayload, VerifyErrors } from 'jsonwebtoken';
import prisma from '../prisma/prisma';
import { AccessDeniedException, HttpException, NotFoundException } from './errors.utils';
import { AccessDeniedException, DeletedException, HttpException, NotFoundException } from './errors.utils';
import { Organization, User, User_Secure_Settings, User_Settings } from '@prisma/client';
import { IncomingHttpHeaders } from 'http';

@@ -150,6 +150,10 @@ export const getOrganization = async (headers: IncomingHttpHeaders, currentUser:
throw new NotFoundException('Organization', organizationid);
}

if (organization.dateDeleted) {
throw new DeletedException('Organization', organization.organizationId);
}

if (!organization.users.some((user) => user.userId === currentUser.userId)) {
throw new AccessDeniedException('Cannot access this organization');
}

0 comments on commit 96c026f

Please sign in to comment.