Skip to content

Commit

Permalink
Add flag to context
Browse files Browse the repository at this point in the history
  • Loading branch information
FSM1 committed Sep 21, 2021
1 parent 84b195f commit eaf6f0d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/files-ui/src/Contexts/FilesApiContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type FilesApiContext = {
validateMasterPassword: (candidatePassword: string) => Promise<boolean>
encryptedEncryptionKey?: string
isMasterPasswordSet: boolean
subscriptionInArrears?: boolean
}

const FilesApiContext = React.createContext<FilesApiContext | undefined>(undefined)
Expand Down Expand Up @@ -62,6 +63,7 @@ const FilesApiProvider = ({ apiUrl, withLocalStorage = true, children }: FilesAp
// access tokens
const [accessToken, setAccessToken] = useState<Token | undefined>(undefined)
const [secured, setSecured] = useState<boolean | undefined>(undefined)
const [subscriptionInArrears, setSubscriptionInArrears] = useState<boolean | undefined>(undefined)
const [refreshToken, setRefreshToken] = useState<Token | undefined>(undefined)
const [decodedRefreshToken, setDecodedRefreshToken] = useState<
{ exp: number; enckey?: string; mps?: string; uuid: string } | undefined
Expand Down Expand Up @@ -216,14 +218,19 @@ const FilesApiProvider = ({ apiUrl, withLocalStorage = true, children }: FilesAp
useEffect(() => {
if (accessToken && accessToken.token && filesApiClient) {
filesApiClient?.setToken(accessToken.token)
const decodedAccessToken = jwtDecode<{ perm: { secured?: string } }>(
const decodedAccessToken = jwtDecode<{ perm: { secured?: string, files?: string } }>(
accessToken.token
)
if (decodedAccessToken.perm.secured === "true") {
setSecured(true)
} else {
setSecured(false)
}
if (decodedAccessToken.perm.files === 'restricted') {
setSubscriptionInArrears(true)
} else {
setSubscriptionInArrears(false)
}
}
}, [accessToken, filesApiClient])

Expand Down Expand Up @@ -308,7 +315,8 @@ const FilesApiProvider = ({ apiUrl, withLocalStorage = true, children }: FilesAp
thresholdKeyLogin,
secureThresholdKeyAccount,
encryptedEncryptionKey: decodedRefreshToken?.enckey,
isMasterPasswordSet: !!decodedRefreshToken?.mps
isMasterPasswordSet: !!decodedRefreshToken?.mps,
subscriptionInArrears
}}
>
{children}
Expand Down

0 comments on commit eaf6f0d

Please sign in to comment.