whodis-react-storage-browser
Version:
React hooks and components for secure, best practices authentication in seconds
23 lines (22 loc) • 1.59 kB
TypeScript
/**
* determines whether the token is synchronized across both environment's storages, to ensure consistent responses
*
* why?
* - browser.localstorage.authorization and browser.cookie.authorization can get out of sync
* - why?
* - browser.localstorage is scoped to each full domain (www.ahbode.com != subdomain.ahbode.com) and per mobile in-app browser launch
* - browser.cookie is scoped simply per browser
* - when the two are out of sync, sad things happen
* - the serverside, which reads only from browser.cookie.authorization, thinks the user is logged in
* - the clientside, which only has the anti-csrf-token in localstorage, can not make authenticated requests -> is effectively logged out
* - the serverside will not redirect the clientside to login before seeing this no longer authorized data
* - the clientside will subsequently break as it tries to make requests it looks like its authorized to do and get back an unauthorized response
* - at best, the client has a bad experience
* - at worst, the client saw data they were no longer authorized to see
* - to ensure this does not happen, we can use a synchronization token that both the server and the client are allowed to see and modify
* - the client can whether it's anti-csrf-token in localstorage in sync with the token that the server has, by comparing the value to the token it has
* - the server can whether the client has been logged out, by checking if the value is now null
*/
export declare const isTokenSynchronized: ({ token }: {
token: string;
}) => boolean;