Browse Source

Merge pull request #137 from ente-io/error-hasSetKey-undefined

throw error if hasSetKey undefined
Neeraj Gupta 3 năm trước cách đây
mục cha
commit
b2d0d719bc
1 tập tin đã thay đổi với 8 bổ sung0 xóa
  1. 8 0
      src/services/userService.ts

+ 8 - 0
src/services/userService.ts

@@ -26,6 +26,8 @@ export interface RecoveryKey {
 }
 const ENDPOINT = getEndpoint();
 
+const HAS_SET_KEYS = 'hasSetKeys';
+
 export interface User {
     id: number;
     name: string;
@@ -133,6 +135,9 @@ export const clearFiles = async () => {
 
 export const isTokenValid = async () => {
     try {
+        if (!getToken()) {
+            return false;
+        }
         const resp = await HTTPService.get(
             `${ENDPOINT}/users/session-validity/v2`,
             null,
@@ -141,6 +146,9 @@ export const isTokenValid = async () => {
             }
         );
         try {
+            if (resp.data[HAS_SET_KEYS] === undefined) {
+                throw Error('resp.data.hasSetKey undefined');
+            }
             if (!resp.data['hasSetKeys']) {
                 try {
                     await putAttributes(