Skip to content

Commit

Permalink
refactor(api): ♻️ added tenantId in session
Browse files Browse the repository at this point in the history
  • Loading branch information
sahrohit committed Sep 19, 2023
1 parent b241dce commit ffdf6f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions apps/api/src/resolvers/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Tenant } from "../entities/Tenant";
export class AdminResolver {
@Query(() => User, { nullable: true })
async meStaff(@Ctx() { req }: MyContext) {
if (!req.session?.userId) {
if (!req.session?.userId || !req.session?.tenantId) {
return null;
}
const user = await User.findOne({
Expand All @@ -26,7 +26,12 @@ export class AdminResolver {
tenant: true,
},
},
where: { id: req.session?.userId },
where: {
id: req.session?.userId,
staff: {
tenantId: req.session?.tenantId,
},
},
});
if (!user?.staff.tenantId) {
return null;
Expand Down Expand Up @@ -84,6 +89,7 @@ export class AdminResolver {
};
}
req.session.userId = user.id;
req.session.tenantId = user.staff.tenantId;
return { user };
}

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Session } from "express-session";
import { type Redis } from "ioredis";

export type MyContext = {
req: Request & { session?: Session & { userId?: number } };
req: Request & { session?: Session & { userId?: number; tenantId?: number } };
res: Response;
redis: Redis;
};

2 comments on commit ffdf6f1

@vercel
Copy link

@vercel vercel bot commented on ffdf6f1 Sep 19, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on ffdf6f1 Sep 19, 2023

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:

ecommerce-admin-client – ./apps/admin

ecommerce-admin-client-git-main-sahrohit.vercel.app
adminpasal.vercel.app
ecommerce-admin-client-sahrohit.vercel.app

Please sign in to comment.