const STORAGE_ACCESS = 'access_token'; const STORAGE_ID = 'id_token'; const STORAGE_EXPIRES = 'expires_at'; const STORAGE_USER = 'user_info'; const STORAGE_STATE = 'auth-state'; const STORAGE_NONCE = 'auth-nonce'; /** * Removes all auth specific items from storage. */ export const clear = () => { localStorage.removeItem(STORAGE_ACCESS); localStorage.removeItem(STORAGE_ID); localStorage.removeItem(STORAGE_EXPIRES); localStorage.removeItem(STORAGE_USER); localStorage.removeItem(STORAGE_STATE); localStorage.removeItem(STORAGE_NONCE); }; export const storeAuth = ({ accessToken, idToken, user, expiresAt, }) => { localStorage.setItem(STORAGE_ACCESS, accessToken); localStorage.setItem(STORAGE_ID, idToken); localStorage.setItem(STORAGE_EXPIRES, expiresAt); localStorage.setItem(STORAGE_USER, JSON.stringify(user)); }; export const storeStateAndNonce = (state, nonce) => { localStorage.setItem(STORAGE_STATE, JSON.stringify(state)); localStorage.setItem(STORAGE_NONCE, nonce); }; export const getStateAndNonce = () => ({ state: localStorage.getItem(STORAGE_STATE), nonce: localStorage.getItem(STORAGE_NONCE), }); export const clearStateAndNonce = () => { localStorage.removeItem(STORAGE_STATE); localStorage.removeItem(STORAGE_NONCE); }; export const getUserInfo = () => JSON.parse(localStorage.getItem(STORAGE_USER)); export const getIdToken = () => localStorage.getItem(STORAGE_ID); export const getExpiresAt = () => JSON.parse(localStorage.getItem(STORAGE_EXPIRES));