File tree 2 files changed +11
-6
lines changed
2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -68,10 +68,11 @@ routes.post(
68
68
Authorization ,
69
69
asyncHandler ( async function logout ( req : Request , res : Response ) {
70
70
const { UserId } = req . getBody ( )
71
+ const userData = req . getState ( 'user' )
71
72
72
- const message = await AuthService . logout ( UserId )
73
+ const message = await AuthService . logout ( UserId , userData )
73
74
const buildResponse = BuildResponse . deleted ( { message } )
74
75
75
- return res . status ( 200 ) . json ( buildResponse )
76
+ return res . clearCookie ( 'token' , { path : '/v1' } ) . json ( buildResponse )
76
77
} )
77
78
)
Original file line number Diff line number Diff line change @@ -156,13 +156,17 @@ class AuthService {
156
156
157
157
/**
158
158
*
159
- * @param userId
159
+ * @param UserId
160
160
*/
161
- public static async logout ( userId : string ) {
162
- const userData = await UserService . getOne ( userId )
161
+ public static async logout ( UserId : string , userData : any ) {
162
+ if ( userData ?. id !== UserId ) {
163
+ throw new ResponseError . Unauthorized ( 'Invalid user login!' )
164
+ }
165
+
166
+ const data = await UserService . getOne ( UserId )
163
167
164
168
// remove refresh token by user id
165
- await RefreshTokenService . delete ( userData . id )
169
+ await RefreshTokenService . delete ( data . id )
166
170
const message = 'You have logged out of the application'
167
171
168
172
return message
You can’t perform that action at this time.
0 commit comments