Skip to content

Commit

Permalink
logout changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MunishSharmaHMCTS committed Nov 21, 2024
1 parent afd56bb commit 32173c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/rpx-xui-node-lib",
"version": "2.29.5-exui-2079-rc7",
"version": "2.29.5-exui-2079-rc8",
"description": "Common nodejs library components for XUI",
"main": "dist/index",
"types": "dist/index.d.ts",
Expand Down
32 changes: 17 additions & 15 deletions src/auth/models/strategy.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export abstract class Strategy extends events.EventEmitter {
}

/* istanbul ignore next */
public logout = async (req: Request, res: Response): Promise<void> => {
public logout = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
const reqSession = req.session as MySessionData

try {
Expand All @@ -185,21 +185,23 @@ export abstract class Strategy extends events.EventEmitter {
})

//passport provides this method on request object
req.logout({ keepSessionInfo: true } as LogOutOptions, (err) => {
console.error(err)
})
await this.destroySession(req)
/* istanbul ignore next */
if (req.query.noredirect) {
res.status(200).send({ message: 'You have been logged out!' })
return Promise.resolve()
}

const redirect = req.query.redirect ? req.query.redirect : AUTH.ROUTE.LOGIN
this.logger.log('redirecting to => ', redirect)
// 401 is when no accessToken
res.redirect(redirect as string)
req.logout(async (err) => {
if (err) {
console.error(err)
return next(err)
}
await this.destroySession(req)
/* istanbul ignore next */
if (req.query.noredirect) {
res.status(200).send({ message: 'You have been logged out!' })
return Promise.resolve()
}

const redirect = req.query.redirect ? req.query.redirect : AUTH.ROUTE.LOGIN
this.logger.log('redirecting to => ', redirect)
// 401 is when no accessToken
res.redirect(redirect as string)
})
/* istanbul ignore next */
} catch (e) {
this.logger.error('error => ', e)
Expand Down

0 comments on commit 32173c3

Please sign in to comment.