Просмотр исходного кода

:sparkles: Finished latest implementation of session/access auth

juan_spike
tomit4 2 лет назад
Родитель
Сommit
9f570f81c2

+ 1
- 4
backend/lib/routes/profile/get.js Просмотреть файл

@@ -28,10 +28,7 @@ module.exports = {
28 28
     options: {
29 29
         ...pluginConfig.docs,
30 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 32
         cors: true,
36 33
         handler: async function (request, h) {
37 34
             const { profile_id } = request.params

+ 1
- 4
backend/lib/routes/user/list-profiles.js Просмотреть файл

@@ -37,10 +37,7 @@ module.exports = {
37 37
     options: {
38 38
         ...pluginConfig.docs,
39 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 41
         cors: true,
45 42
         handler: async function (request, h) {
46 43
             const { userService, profileService } = request.server.services()

+ 1
- 3
backend/lib/routes/user/user-by-email.js Просмотреть файл

@@ -18,9 +18,7 @@ module.exports = {
18 18
     options: {
19 19
         ...pluginConfig.docs.get,
20 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 22
         cors: true,
25 23
         handler: async function (request, h) {
26 24
             const email = request.params.email

+ 1
- 1
backend/lib/services/user.js Просмотреть файл

@@ -116,7 +116,7 @@ module.exports = class UserService extends Schmervice.Service {
116 116
     }
117 117
 
118 118
     /**
119
-     * Use knew to find first user with useremail
119
+     * Use to find first user with useremail
120 120
      * @param {*} username
121 121
      * @param {*} txn
122 122
      * @returns

+ 7
- 4
frontend/src/services/profile.service.js Просмотреть файл

@@ -8,8 +8,11 @@ import { Profile } from '../entities/profile/profile.js'
8 8
  * @param {number} userId
9 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 16
     const validProfileInstances = []
14 17
     for (let profileData of profilesForUserId) {
15 18
         const profile = new Profile(profileData)
@@ -25,10 +28,10 @@ const createProfileForUserId = async (userId, responses) => {
25 28
     return profile
26 29
 }
27 30
 
28
-const fetchProfileByProfileId = async profileId => {
31
+const fetchProfileByProfileId = async (profileId, sessionToken) => {
29 32
     let profile
30 33
     try {
31
-        const profileData = await db.get(`/profile/${profileId}`)
34
+        const profileData = await db.get(`/profile/${profileId}`, sessionToken)
32 35
         profile = new Profile(profileData)
33 36
         if (!profile.isValid()) {
34 37
             throw '[Profile Service error]: Invalid or incomplete profile returned.'

+ 2
- 2
frontend/src/services/user.service.js Просмотреть файл

@@ -14,8 +14,8 @@ const signupUser = async user => {
14 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 21
 export { signupUser, fetchUserByEmail }

+ 26
- 10
frontend/src/views/OnboardingView.vue Просмотреть файл

@@ -76,10 +76,17 @@ export default {
76 76
             // TODO: Validate All routes hit by these methods using tokens in headers
77 77
             // NOTE: This can be accomplished using sessionData.sessionToken,
78 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 87
             this.responses = await this.grabResponsesByProfileId(
82 88
                 currentProfileId,
89
+                sessionData.sessionToken,
83 90
             )
84 91
             this.currentStep = this.responses.length + 3
85 92
             this.goToStep(this.currentStep)
@@ -119,14 +126,17 @@ export default {
119 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 131
             if (!user) {
125 132
                 throw new Error('User NOT found by email')
126 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 140
             if (
131 141
                 profilesFromUserId.length === 1 &&
132 142
                 profilesFromUserId.status !== 401
@@ -139,17 +149,23 @@ export default {
139 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 157
             if (!profile || profile.status === 401) {
145 158
                 throw new Error(`No Profile Found for profileId ${profileId}`)
146 159
             } else {
147 160
                 return profile
148 161
             }
149 162
         },
150
-        async grabResponsesByProfileId(profileId) {
163
+        async grabResponsesByProfileId(profileId, sessionToken) {
151 164
             const responses = []
152
-            const profile = await this.grabProfileByProfileId(profileId)
165
+            const profile = await this.grabProfileByProfileId(
166
+                profileId,
167
+                sessionToken,
168
+            )
153 169
             if (!profile.responses.length || profile.responses.status === 401) {
154 170
                 throw new Error(`No Responses Found for profileId ${profileId}`)
155 171
             } else {

Загрузка…
Отмена
Сохранить