瀏覽代碼

feat: sessionToken review

ryanemax 3 周之前
父節點
當前提交
3dc045f214
共有 1 個文件被更改,包括 16 次插入6 次删除
  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")
         }