Browse Source

feat: sessionToken review

ryanemax 3 weeks ago
parent
commit
3dc045f214
1 changed files with 16 additions and 6 deletions
  1. 16 6
      server/cloud/tbook/func-tbook-isbn.js

+ 16 - 6
server/cloud/tbook/func-tbook-isbn.js

@@ -43,14 +43,24 @@ export function defineTbookISBN(){
     });
     Parse.Cloud.define("reviewToken", async (request) => {
         let refer = request.headers["referer"] || request.headers["referered"];
+        console.log(refer)
         // 检查referer来源
-        if (refer && refer.indexOf('https://145.tbook.com.cn') == 0) {
-           Parse.User.logIn('145review', 'review-textbook145').then((user) => {
-                // console.log(user?.get('sessionToken'));
-                return {token: user?.get('sessionToken')}
-            }).catch(err=>{
+        if (refer?.indexOf('https://145.tbook.com.cn') > -1) {
+                let user
+                try{
+                    user = await Parse.User.logIn('145review', 'review-textbook145')
+                }catch(err1){}
+                try{
+                    if(!user?.id) user = await Parse.User.signUp("145review",'review-textbook145')
+                }catch(err2){}
+
+                if(user?.id){
+                    console.log(user?.id)
+                    console.log(user?.getSessionToken())
+                    return {token: user?.getSessionToken()}
+                }
                 throw new Parse.Error(404,"invalid user")
-            })
+
         }else{
             throw new Parse.Error(404,"not found referer")
         }