ソースを参照

first working api

tags/0.0.1^2
diaseu 3年前
コミット
81b85c411a
2個のファイルの変更8行の追加9行の削除
  1. 3
    3
      backend/lib/routes/user/authentication.js
  2. 5
    6
      backend/lib/services/user.js

+ 3
- 3
backend/lib/routes/user/authentication.js ファイルの表示

@@ -27,13 +27,13 @@ module.exports = {
27 27
         tags: ['api'],
28 28
         // auth: 'default_jwt',
29 29
         auth: false,
30
+        cors: true,
30 31
         handler: async function (request, h) {
31 32
             try {
32
-
33
+                const { userService } = request.services()
33 34
                 const userEmail = request.params.user_email
34 35
 
35
-                const { userService } = request.services()
36
-                const password = userService.getPassword(userEmail)
36
+                const password = await userService.getPassword(userEmail)
37 37
 
38 38
                 return {
39 39
                     ok: true,

+ 5
- 6
backend/lib/services/user.js ファイルの表示

@@ -97,8 +97,6 @@ module.exports = class UserService extends Schmervice.Service {
97 97
         return id
98 98
     }
99 99
 
100
-
101
-
102 100
     /**
103 101
      * Self explanatory
104 102
      * @param {*} param0
@@ -171,10 +169,11 @@ module.exports = class UserService extends Schmervice.Service {
171 169
 
172 170
     async getPassword(email, txn) {
173 171
         const { Auth } = this.server.models()
174
-
175
-        const password = await Auth.query(txn)
176
-            .where('user_email', email)
177 172
         
178
-        return password.token
173
+        const passwordRow = await Auth.query(txn)
174
+            .where('user_email', email)
175
+            .first()
176
+    
177
+        return passwordRow ? passwordRow.token : null
179 178
     }
180 179
 }

読み込み中…
キャンセル
保存