Procházet zdrojové kódy

:recycle: tweak login cookie | don't pass session key string around just set default arg

brian_lifecycle_docs
j před 2 roky
rodič
revize
917746c00c

+ 1
- 3
frontend/src/router/guards.js Zobrazit soubor

@@ -15,9 +15,7 @@ async function log(to) {
15 15
 }
16 16
 
17 17
 const loginIfToken = async () => {
18
-    const sessionData = await authenticator.verifySessionCookie(
19
-        'siimee_session',
20
-    )
18
+    const sessionData = await authenticator.verifySessionCookie()
21 19
     if (
22 20
         sessionData?.profileId &&
23 21
         sessionData?.sessionToken &&

+ 6
- 10
frontend/src/services/auth.service.js Zobrazit soubor

@@ -25,20 +25,16 @@ class Authenticator {
25 25
             prev[name] = value.join('=')
26 26
             return prev
27 27
         }, {})
28
-        const cookieVal =
29
-            cookieKey in cookies ? cookies[`${cookieKey}`] : undefined
30
-        return cookieVal
28
+        return cookies[cookieKey]
31 29
     }
32
-    async verifySessionCookie(sessionCookie) {
33
-        const hashedAccessToken = this.grabStoredCookie(sessionCookie)
30
+    async verifySessionCookie(sessionCookieKey = 'siimee_session') {
31
+        const hashedAccessToken = this.grabStoredCookie(sessionCookieKey)
34 32
         if (!hashedAccessToken)
35 33
             return console.warn('WARNING :=> accessToken is not defined')
36 34
         const validatedToken = await this.validateSession(hashedAccessToken)
37
-        if (validatedToken.error) {
38
-            console.error('ERROR :=>', validatedToken.error)
39
-        } else {
40
-            return validatedToken
41
-        }
35
+        if (validatedToken.error)
36
+            return console.error('ERROR :=>', validatedToken.error)
37
+        return validatedToken
42 38
     }
43 39
 }
44 40
 const authenticator = new Authenticator()

+ 1
- 1
frontend/src/views/LoginView.vue Zobrazit soubor

@@ -55,7 +55,7 @@ export default {
55 55
             if (sessionInfo.emailSentSuccessfully) {
56 56
                 this.emailSentSuccessfully = true
57 57
             }
58
-            document.cookie = `siimee_session=${sessionInfo.hashedSessionToken}; max-age=600; path=/`
58
+            document.cookie = `siimee_session=${sessionInfo.hashedSessionToken}; max-age=600; path=/; SameSite=Lax`
59 59
         },
60 60
     },
61 61
 }

+ 2
- 4
frontend/src/views/OnboardingView.vue Zobrazit soubor

@@ -60,9 +60,7 @@ export default {
60 60
         // TODO: Troubleshoot bug where not all responses are returned at SurveyCompleteView
61 61
         this.survey = await surveyFactory.createSurvey()
62 62
         try {
63
-            const sessionData = await authenticator.verifySessionCookie(
64
-                'siimee_session',
65
-            )
63
+            const sessionData = await authenticator.verifySessionCookie()
66 64
             if (sessionData) {
67 65
                 this.responses = this.formatResponses(
68 66
                     currentProfile._profile.responses,
@@ -115,7 +113,7 @@ export default {
115 113
                 )
116 114
                 currentProfile._profile.responses = this.responses
117 115
                 try {
118
-                    await authenticator.verifySessionCookie('siimee_session')
116
+                    await authenticator.verifySessionCookie()
119 117
                 } catch (err) {
120 118
                     this.currentStep = 0
121 119
                     this.goToStep(this.currentStep)

+ 1
- 2
frontend/src/views/VerifyView.vue Zobrazit soubor

@@ -14,8 +14,7 @@ export default {
14 14
         try {
15 15
             this.isHashInUrl(hash)
16 16
             await this.verifyActiveSession(hash)
17
-            const sessionData =
18
-                await authenticator.verifySessionCookie('siimee_session')
17
+            const sessionData = await authenticator.verifySessionCookie()
19 18
             currentProfile.login(
20 19
                 sessionData.profileId,
21 20
                 this.$waveui.notify,

Načítá se…
Zrušit
Uložit