Kaynağa Gözat

:pencil2: Cleaned up if statements, less nesting

juan_spike
tomit4 3 yıl önce
ebeveyn
işleme
cca081243e

+ 1
- 1
backend/lib/services/user.js Dosyayı Görüntüle

243
      */
243
      */
244
     validateToken(token) {
244
     validateToken(token) {
245
         const key = this.server.registrations['main-app-plugin'].options.jwtKey
245
         const key = this.server.registrations['main-app-plugin'].options.jwtKey
246
-        const decodedToken = Jwt.token.decode(token)
247
         // NOTE: reveals email...perhaps unhashed email belongs here instead...
246
         // NOTE: reveals email...perhaps unhashed email belongs here instead...
248
         try {
247
         try {
248
+            const decodedToken = Jwt.token.decode(token)
249
             Jwt.token.verify(decodedToken, key)
249
             Jwt.token.verify(decodedToken, key)
250
             return { isValid: true, payload: decodedToken.decoded.payload }
250
             return { isValid: true, payload: decodedToken.decoded.payload }
251
         } catch (err) {
251
         } catch (err) {

+ 25
- 32
frontend/src/views/OnboardingView.vue Dosyayı Görüntüle

65
     async created() {
65
     async created() {
66
         this.survey = await surveyFactory.createSurvey()
66
         this.survey = await surveyFactory.createSurvey()
67
         this.authenticator = new Authenticator()
67
         this.authenticator = new Authenticator()
68
-        if (document.cookie.length) {
69
-            const sessionToken = this.grabCookie('siimee_session_onboarding')
70
-            if (sessionToken) {
71
-                const sessionData = await this.authenticator.validateJwt(
72
-                    sessionToken,
73
-                )
74
-                // NOTE: Left off here, INCOMPLETE, no ACCESS TOKEN yet, crazy amount of logic here...
75
-                if (sessionData.isValid) {
76
-                    const userEmail = sessionData.payload.email
77
-                    const emailIsInCache =
78
-                        await this.authenticator.checkEmailCache(userEmail)
79
-                    if (emailIsInCache) {
80
-                        const user = await fetchUserByEmail(userEmail)
81
-                        const userId = user.user_id
82
-                        const profilesFromUserId = await fetchProfilesByUserId(
83
-                            userId,
84
-                        )
85
-                        let profileId
86
-                        if (profilesFromUserId.length === 1) {
87
-                            profileId = profilesFromUserId[0].profile_id
88
-                            this.currentProfileId = profileId
89
-                        }
90
-                        const profile = await fetchProfileByProfileId(profileId)
91
-                        profile.responses.forEach(response => {
92
-                            this.responses.push({
93
-                                response_key_id: response.response_key_id,
94
-                                val: response.val,
95
-                            })
96
-                        })
97
-                        this.currentStep = this.responses.length + 3
98
-                        this.goToStep(this.currentStep)
99
-                    }
68
+        const sessionToken = this.grabCookie('siimee_session_onboarding')
69
+        const sessionData = await this.authenticator.validateJwt(sessionToken)
70
+        // NOTE: Left off here, INCOMPLETE, no ACCESS TOKEN yet, crazy amount of logic here...
71
+        if (sessionData.isValid) {
72
+            const userEmail = sessionData.payload.email
73
+            const emailIsInCache = await this.authenticator.checkEmailCache(
74
+                userEmail,
75
+            )
76
+            if (emailIsInCache) {
77
+                const user = await fetchUserByEmail(userEmail)
78
+                const userId = user.user_id
79
+                const profilesFromUserId = await fetchProfilesByUserId(userId)
80
+                let profileId
81
+                if (profilesFromUserId.length === 1) {
82
+                    profileId = profilesFromUserId[0].profile_id
83
+                    this.currentProfileId = profileId
100
                 }
84
                 }
85
+                const profile = await fetchProfileByProfileId(profileId)
86
+                profile.responses.forEach(response => {
87
+                    this.responses.push({
88
+                        response_key_id: response.response_key_id,
89
+                        val: response.val,
90
+                    })
91
+                })
92
+                this.currentStep = this.responses.length + 3
93
+                this.goToStep(this.currentStep)
101
             }
94
             }
102
         }
95
         }
103
     },
96
     },

Loading…
İptal
Kaydet