Bläddra i källkod

:recycle: better error messages for sessin token processing

neo
toj 2 år sedan
förälder
incheckning
da0195ff62

+ 2
- 0
backend/lib/routes/user/validate-session.js Visa fil

@@ -33,6 +33,8 @@ module.exports = {
33 33
             try {
34 34
                 const validatedSessionToken =
35 35
                     userService.validateSession(hashedSessionToken)
36
+                if(validatedSessionToken?.email) throw new Error(`Could not validate token based on request: ${request}`)
37
+                
36 38
                 const user = await userService.findByUserEmail(
37 39
                     validatedSessionToken.email,
38 40
                 )

+ 5
- 0
backend/lib/services/user.js Visa fil

@@ -253,6 +253,11 @@ module.exports = class UserService extends Schmervice.Service {
253 253
      * @returns {PayloadFromActiveSessions}
254 254
      */
255 255
     validateSession(hashedSessionToken) {
256
+        if (!hashedSessionToken) {
257
+            throw new Error(
258
+                'hashedSessionToken not passed!',
259
+            )
260
+        }
256 261
         const userSession = this.activeSessions[hashedSessionToken]
257 262
         if (!userSession) {
258 263
             throw new Error(

+ 3
- 2
frontend/src/views/VerifyView.vue Visa fil

@@ -18,11 +18,12 @@ export default {
18 18
             sessionData = await authenticator.verifySession(hash)
19 19
             if (!sessionData.hashesMatch)
20 20
                 throw new Error('Hash is not in activeSessions!')
21
+            
22
+            /** Check if session was confirmed and is now valid in guard*/
23
+            this.$router.push('/')
21 24
         } catch (err) {
22 25
             console.error(err)
23 26
         }
24
-        /** Check if session was confirmed and is now valid in guard*/
25
-        this.$router.push('/')
26 27
     }
27 28
 }
28 29
 </script>

Laddar…
Avbryt
Spara