forked from verdnatura/salix-front
Reviewed-on: verdnatura/salix-front#299 Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
commit
55dd401064
|
@ -3,31 +3,29 @@ import { useRole } from './useRole';
|
|||
import { useUserConfig } from './useUserConfig';
|
||||
import axios from 'axios';
|
||||
import useNotify from './useNotify';
|
||||
const TOKEN_MULTIMEDIA = 'tokenMultimedia';
|
||||
const TOKEN = 'token';
|
||||
|
||||
export function useSession() {
|
||||
const { notify } = useNotify();
|
||||
|
||||
function getToken() {
|
||||
const localToken = localStorage.getItem('token');
|
||||
const sessionToken = sessionStorage.getItem('token');
|
||||
const localToken = localStorage.getItem(TOKEN);
|
||||
const sessionToken = sessionStorage.getItem(TOKEN);
|
||||
|
||||
return localToken || sessionToken || '';
|
||||
}
|
||||
function getTokenMultimedia() {
|
||||
const localTokenMultimedia = localStorage.getItem('token'); // Temporal
|
||||
const sessionTokenMultimedia = sessionStorage.getItem('token'); // Temporal
|
||||
const localTokenMultimedia = localStorage.getItem();
|
||||
const sessionTokenMultimedia = sessionStorage.getItem(TOKEN_MULTIMEDIA);
|
||||
|
||||
return localTokenMultimedia || sessionTokenMultimedia || '';
|
||||
}
|
||||
|
||||
function setToken(data) {
|
||||
if (data.keepLogin) {
|
||||
localStorage.setItem('token', data.token);
|
||||
localStorage.setItem('tokenMultimedia', data.tokenMultimedia);
|
||||
} else {
|
||||
sessionStorage.setItem('token', data.token);
|
||||
sessionStorage.setItem('tokenMultimedia', data.tokenMultimedia);
|
||||
}
|
||||
const storage = data.keepLogin ? localStorage : sessionStorage;
|
||||
storage.setItem(TOKEN, data.token);
|
||||
storage.setItem(TOKEN_MULTIMEDIA, data.tokenMultimedia);
|
||||
}
|
||||
async function destroyToken(url, storage, key) {
|
||||
if (storage.getItem(key)) {
|
||||
|
@ -71,8 +69,8 @@ export function useSession() {
|
|||
}
|
||||
|
||||
function isLoggedIn() {
|
||||
const localToken = localStorage.getItem('token');
|
||||
const sessionToken = sessionStorage.getItem('token');
|
||||
const localToken = localStorage.getItem(TOKEN);
|
||||
const sessionToken = sessionStorage.getItem(TOKEN);
|
||||
|
||||
return !!(localToken || sessionToken);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue