Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: store only user ID in session #1849

Merged
merged 5 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/modules/auth/__tests__/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe('auth.controller', () => {

// Assert
expect(mockRes.status).toBeCalledWith(200)
expect(mockRes.json).toBeCalledWith(mockUser.toObject())
expect(mockRes.json).toBeCalledWith(mockUser)
})

it('should return 401 when retrieving agency returns InvalidDomainError', async () => {
Expand Down
9 changes: 4 additions & 5 deletions src/app/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,15 @@ export const handleLoginVerifyOtp: RequestHandler<
.json(coreErrorMessage)
}

// TODO(#212): Should store only userId in session.
// Add user info to session.
const userObj = user.toObject() as SessionUser
req.session.user = userObj
const { _id } = user.toObject() as SessionUser
req.session.user = { _id }
logger.info({
message: `Successfully logged in user ${user.email}`,
message: `Successfully logged in user ${user}`,
meta: logMeta,
})

return res.status(StatusCodes.OK).json(userObj)
return res.status(StatusCodes.OK).json(user)
})
// Step 3b: Error occured in one of the steps.
.mapErr((error) => {
Expand Down
4 changes: 2 additions & 2 deletions src/types/vendor/express.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ declare global {
}

export interface Session {
user?: IUserSchema
user?: IUserSchema['_id']
karrui marked this conversation as resolved.
Show resolved Hide resolved
}

export interface AuthedSession extends Session {
user: IUserSchema
user: IUserSchema['_id']
karrui marked this conversation as resolved.
Show resolved Hide resolved
}
}
}