Skip to content

Commit

Permalink
fixing session issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AvinashMudunuri committed Aug 21, 2024
1 parent 64b26b1 commit 006016e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 8 additions & 4 deletions controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ class UserController {
async logout(req, res) {
try {
const token = req.header('Authorization').replace('Bearer ', '');
await sessionService.deleteSession(token);
res.status(200).json({
message: 'Logout Successful',
});
const response = await sessionService.deleteSession(token);
if (repsonse) {
res.status(200).json({
message: 'Logout Successful',
});
} else {
res.status(500).send({ error: 'User with this token doesnot exists' });
}
} catch (e) {
res.status(500).json({
error: 'Could not logout, please try again',
Expand Down
7 changes: 6 additions & 1 deletion domain/services/sessionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ class SessionService {
return await sessionRepository.createSession(data);
}
async deleteSession(token) {
return await sessionRepository.deleteSession(token);
const session = await sessionRepository.deleteSession(token);
if (session) {
return session
} else {
throw new Error('Session with this token doesnot exists');
}
}
async getSessionByToken(token) {
return await sessionRepository.findByToken(token);
Expand Down

0 comments on commit 006016e

Please sign in to comment.