Skip to content

Commit

Permalink
refactor: move token check into the if scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahdiyeh Amirkhani authored and Mahdiyeh Amirkhani committed Jul 27, 2023
1 parent 4c01b6d commit bd0228d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/api/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ const AUTH_REQUIRED_ENDPOINTS = [
export const isAuthorized = (name: TSocketEndpointNames) => {
let is_authorized = true;

const accounts = JSON.parse(localStorage.getItem('client.accounts') || '{}');
const active_loginid = localStorage.getItem('active_loginid');
const current_token = accounts?.[active_loginid || '']?.token;

if (AUTH_REQUIRED_ENDPOINTS.includes(name)) {
const accounts = JSON.parse(localStorage.getItem('client.accounts') || '{}');
const active_loginid = localStorage.getItem('active_loginid');
const current_token = accounts?.[active_loginid || '']?.token;
const state = queryClient.getQueryState<TSocketResponseData<'authorize'>>([
'authorize',
JSON.stringify({ authorize: current_token }),
Expand Down

0 comments on commit bd0228d

Please sign in to comment.