소스 검색

:recycle: trim down validate session route further

brian_auth_fix
j 2 년 전
부모
커밋
a2c564079d
2개의 변경된 파일8개의 추가작업 그리고 15개의 파일을 삭제
  1. 7
    10
      backend/lib/routes/user/validate-session.js
  2. 1
    5
      backend/lib/services/user.js

+ 7
- 10
backend/lib/routes/user/validate-session.js 파일 보기

@@ -54,20 +54,17 @@ module.exports = {
54 54
                 const sessionTokenIsValid = userService.validateToken(
55 55
                     userSession.sessionToken,
56 56
                 )
57
-                if (sessionTokenIsValid.message) {
58
-                    throw new Error(sessionTokenIsValid.message)
57
+                if (!sessionTokenIsValid) {
58
+                    throw new Error(
59
+                        `Could not validate session token: ${userSession.sessionToken}`,
60
+                    )
59 61
                 }
60
-                const validatedSessionInfo = sessionTokenIsValid
61
-                    ? userSession
62
-                    : { ...sessionTokenIsValid }
63
-
64
-                if (validatedSessionInfo?.email)
62
+                if (userSession?.email)
65 63
                     throw new Error(
66 64
                         `Could not validate token based on payload: ${request.payload}`,
67 65
                     )
68
-
69 66
                 const user = await userService.findByUserEmail(
70
-                    validatedSessionInfo.email,
67
+                    userSession.email,
71 68
                 )
72 69
                 const type = user.is_poster === 1 ? 'poster' : 'seeker'
73 70
                 const profiles = await profileService.getCompleteProfilesFor(
@@ -80,7 +77,7 @@ module.exports = {
80 77
                     ok: true,
81 78
                     handler: pluginConfig.handlerType,
82 79
                     data: {
83
-                        ...validatedSessionInfo,
80
+                        ...userSession,
84 81
                         profileId: profileId,
85 82
                     },
86 83
                 }

+ 1
- 5
backend/lib/services/user.js 파일 보기

@@ -240,11 +240,7 @@ module.exports = class UserService extends Schmervice.Service {
240 240
      */
241 241
     validateToken(token) {
242 242
         const key = process.env.APP_SECRET
243
-        try {
244
-            return JWT.verify(token, key)
245
-        } catch (err) {
246
-            return { payload: null, message: err.message }
247
-        }
243
+        return JWT.verify(token, key)
248 244
     }
249 245
     removeSession(hashedSessionToken) {
250 246
         const userSession = this.activeSessions[hashedSessionToken]

Loading…
취소
저장