Skip to content

Commit

Permalink
Fixed: code to handle the case when logout promise rejects(#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymaheshwari1 committed May 27, 2024
1 parent d48daa2 commit d3d2162
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/store/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,17 @@ export const useAuthStore = defineStore('authStore', {
// if the user is already unauthorised then not calling the logout api as it returns 401 again that results in a loop, thus there is no need to call logout api if the user is unauthorised
if(!payload?.isUserUnauthorised) {
emitter.emit("presentLoader",{ message: "Logging out...", backdropDismiss: false });
await logout();

// wrapping the parsing logic in try catch as in some case the logout api makes redirection, and then we are unable to parse the resp and thus the logout process halts
try {
let resp;
resp = await logout();

// Added logic to remove the `//` from the resp as in case of get request we are having the extra characters and in case of post we are having 403
resp = JSON.parse(resp.startsWith('//') ? resp.replace('//', '') : resp)

Check warning on line 104 in src/store/auth.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'resp' is assigned a value but never used

Check warning on line 104 in src/store/auth.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'resp' is assigned a value but never used
} catch(err) {
console.error('Error parsing data', err)

Check warning on line 106 in src/store/auth.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

Unexpected console statement

Check warning on line 106 in src/store/auth.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

Unexpected console statement
}
}

// resetting the whole state except oms
Expand Down

0 comments on commit d3d2162

Please sign in to comment.