Procházet zdrojové kódy

:sparkles: Finished latest implementation of session/access auth

tags/0.0.3^2
tomit4 před 2 roky
rodič
revize
a0f6fd2e65

+ 1
- 4
backend/lib/routes/profile/get.js Zobrazit soubor

28
     options: {
28
     options: {
29
         ...pluginConfig.docs,
29
         ...pluginConfig.docs,
30
         tags: ['api'],
30
         tags: ['api'],
31
-        /** Protect this route with authentication? */
32
-        // TODO: change this once sessionToken is passed in headers
33
-        auth: false,
34
-        // auth: 'default_jwt',
31
+        auth: 'default_jwt',
35
         cors: true,
32
         cors: true,
36
         handler: async function (request, h) {
33
         handler: async function (request, h) {
37
             const { profile_id } = request.params
34
             const { profile_id } = request.params

+ 1
- 4
backend/lib/routes/user/list-profiles.js Zobrazit soubor

37
     options: {
37
     options: {
38
         ...pluginConfig.docs,
38
         ...pluginConfig.docs,
39
         tags: ['api'],
39
         tags: ['api'],
40
-        /** Protect this route with authentication? */
41
-        // TODO: change this once sessionToken is passed in headers
42
-        auth: false,
43
-        // auth: 'default_jwt',
40
+        auth: 'default_jwt',
44
         cors: true,
41
         cors: true,
45
         handler: async function (request, h) {
42
         handler: async function (request, h) {
46
             const { userService, profileService } = request.server.services()
43
             const { userService, profileService } = request.server.services()

+ 1
- 3
backend/lib/routes/user/user-by-email.js Zobrazit soubor

18
     options: {
18
     options: {
19
         ...pluginConfig.docs.get,
19
         ...pluginConfig.docs.get,
20
         tags: ['api'],
20
         tags: ['api'],
21
-        auth: false,
22
-        // TODO: change this once sessionToken is passed in headers
23
-        // auth: 'default_jwt',
21
+        auth: 'default_jwt',
24
         cors: true,
22
         cors: true,
25
         handler: async function (request, h) {
23
         handler: async function (request, h) {
26
             const email = request.params.email
24
             const email = request.params.email

+ 1
- 1
backend/lib/services/user.js Zobrazit soubor

116
     }
116
     }
117
 
117
 
118
     /**
118
     /**
119
-     * Use knew to find first user with useremail
119
+     * Use to find first user with useremail
120
      * @param {*} username
120
      * @param {*} username
121
      * @param {*} txn
121
      * @param {*} txn
122
      * @returns
122
      * @returns

+ 7
- 4
frontend/src/services/profile.service.js Zobrazit soubor

8
  * @param {number} userId
8
  * @param {number} userId
9
  * @returns {array} instantiated Profile objects (see: /entites/profile)
9
  * @returns {array} instantiated Profile objects (see: /entites/profile)
10
  */
10
  */
11
-const fetchProfilesByUserId = async userId => {
12
-    const profilesForUserId = await db.get(`/user/${userId}/profiles`)
11
+const fetchProfilesByUserId = async (userId, sessionToken) => {
12
+    const profilesForUserId = await db.get(
13
+        `/user/${userId}/profiles`,
14
+        sessionToken,
15
+    )
13
     const validProfileInstances = []
16
     const validProfileInstances = []
14
     for (let profileData of profilesForUserId) {
17
     for (let profileData of profilesForUserId) {
15
         const profile = new Profile(profileData)
18
         const profile = new Profile(profileData)
25
     return profile
28
     return profile
26
 }
29
 }
27
 
30
 
28
-const fetchProfileByProfileId = async profileId => {
31
+const fetchProfileByProfileId = async (profileId, sessionToken) => {
29
     let profile
32
     let profile
30
     try {
33
     try {
31
-        const profileData = await db.get(`/profile/${profileId}`)
34
+        const profileData = await db.get(`/profile/${profileId}`, sessionToken)
32
         profile = new Profile(profileData)
35
         profile = new Profile(profileData)
33
         if (!profile.isValid()) {
36
         if (!profile.isValid()) {
34
             throw '[Profile Service error]: Invalid or incomplete profile returned.'
37
             throw '[Profile Service error]: Invalid or incomplete profile returned.'

+ 2
- 2
frontend/src/services/user.service.js Zobrazit soubor

14
     return await db.post(`/user/signup`, payload)
14
     return await db.post(`/user/signup`, payload)
15
 }
15
 }
16
 
16
 
17
-const fetchUserByEmail = async userEmail => {
18
-    return await db.get(`/user/fetchbymail/${userEmail}`)
17
+const fetchUserByEmail = async (userEmail, sessionToken) => {
18
+    return await db.get(`/user/fetchbymail/${userEmail}`, sessionToken)
19
 }
19
 }
20
 
20
 
21
 export { signupUser, fetchUserByEmail }
21
 export { signupUser, fetchUserByEmail }

+ 26
- 10
frontend/src/views/OnboardingView.vue Zobrazit soubor

76
             // TODO: Validate All routes hit by these methods using tokens in headers
76
             // TODO: Validate All routes hit by these methods using tokens in headers
77
             // NOTE: This can be accomplished using sessionData.sessionToken,
77
             // NOTE: This can be accomplished using sessionData.sessionToken,
78
             // as it currently has the raw session token in it
78
             // as it currently has the raw session token in it
79
-            const userId = await this.grabUserIdByEmail(sessionData.email)
80
-            currentProfileId = await this.grabProfileIdByUserId(userId)
79
+            const userId = await this.grabUserIdByEmail(
80
+                sessionData.email,
81
+                sessionData.sessionToken,
82
+            )
83
+            currentProfileId = await this.grabProfileIdByUserId(
84
+                userId,
85
+                sessionData.sessionToken,
86
+            )
81
             this.responses = await this.grabResponsesByProfileId(
87
             this.responses = await this.grabResponsesByProfileId(
82
                 currentProfileId,
88
                 currentProfileId,
89
+                sessionData.sessionToken,
83
             )
90
             )
84
             this.currentStep = this.responses.length + 3
91
             this.currentStep = this.responses.length + 3
85
             this.goToStep(this.currentStep)
92
             this.goToStep(this.currentStep)
119
                 return validatedToken
126
                 return validatedToken
120
             }
127
             }
121
         },
128
         },
122
-        async grabUserIdByEmail(email) {
123
-            const user = await fetchUserByEmail(email)
129
+        async grabUserIdByEmail(email, sessionToken) {
130
+            const user = await fetchUserByEmail(email, sessionToken)
124
             if (!user) {
131
             if (!user) {
125
                 throw new Error('User NOT found by email')
132
                 throw new Error('User NOT found by email')
126
             } else return user.user_id
133
             } else return user.user_id
127
         },
134
         },
128
-        async grabProfileIdByUserId(userId) {
129
-            const profilesFromUserId = await fetchProfilesByUserId(userId)
135
+        async grabProfileIdByUserId(userId, sessionToken) {
136
+            const profilesFromUserId = await fetchProfilesByUserId(
137
+                userId,
138
+                sessionToken,
139
+            )
130
             if (
140
             if (
131
                 profilesFromUserId.length === 1 &&
141
                 profilesFromUserId.length === 1 &&
132
                 profilesFromUserId.status !== 401
142
                 profilesFromUserId.status !== 401
139
                 throw new Error('No Profile for User ID found')
149
                 throw new Error('No Profile for User ID found')
140
             }
150
             }
141
         },
151
         },
142
-        async grabProfileByProfileId(profileId) {
143
-            const profile = await fetchProfileByProfileId(profileId)
152
+        async grabProfileByProfileId(profileId, sessionToken) {
153
+            const profile = await fetchProfileByProfileId(
154
+                profileId,
155
+                sessionToken,
156
+            )
144
             if (!profile || profile.status === 401) {
157
             if (!profile || profile.status === 401) {
145
                 throw new Error(`No Profile Found for profileId ${profileId}`)
158
                 throw new Error(`No Profile Found for profileId ${profileId}`)
146
             } else {
159
             } else {
147
                 return profile
160
                 return profile
148
             }
161
             }
149
         },
162
         },
150
-        async grabResponsesByProfileId(profileId) {
163
+        async grabResponsesByProfileId(profileId, sessionToken) {
151
             const responses = []
164
             const responses = []
152
-            const profile = await this.grabProfileByProfileId(profileId)
165
+            const profile = await this.grabProfileByProfileId(
166
+                profileId,
167
+                sessionToken,
168
+            )
153
             if (!profile.responses.length || profile.responses.status === 401) {
169
             if (!profile.responses.length || profile.responses.status === 401) {
154
                 throw new Error(`No Responses Found for profileId ${profileId}`)
170
                 throw new Error(`No Responses Found for profileId ${profileId}`)
155
             } else {
171
             } else {

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