@sheenarbw/redux-drf-sagas
Version:
If you are running Django Rest Framework on your backend then you can use these tools to get your js frontend to play nice with your backend. It's framework agnostic. It doesn't mean you would need to use redux as your main state management tool
21 lines (16 loc) • 536 B
JavaScript
const AUTH_TOKEN = '_auth_token';
export const getAuthToken = () => {
const token =
sessionStorage.getItem(AUTH_TOKEN) || localStorage.getItem(AUTH_TOKEN);
if (token !== 'undefined') return token;
};
export const clearAuthToken = () => {
sessionStorage.removeItem(AUTH_TOKEN);
localStorage.removeItem(AUTH_TOKEN);
};
export const setAuthToken = ({ value, keep }) => {
if (value) {
if (keep) localStorage.setItem(AUTH_TOKEN, value);
else sessionStorage.setItem(AUTH_TOKEN, value);
} else clearAuthToken();
};