Cosmos-Server/client/src/utils/hooks.js

29 lines
602 B
JavaScript
Raw Permalink Normal View History

2023-10-04 17:26:47 +00:00
import React from 'react';
import { useCookies } from 'react-cookie';
import { logout } from '../api/authentication';
function useClientInfos() {
2023-10-07 13:53:20 +00:00
const [cookies] = useCookies(['client-infos']);
2023-10-07 13:37:40 +00:00
2023-10-04 17:26:47 +00:00
let clientInfos = null;
try {
// Try to parse the cookie into a JavaScript object
clientInfos = cookies['client-infos'].split(',');
2023-10-07 13:37:40 +00:00
return {
nickname: clientInfos[0],
role: clientInfos[1]
};
2023-10-04 17:26:47 +00:00
} catch (error) {
console.error('Error parsing client-infos cookie:', error);
2023-10-07 13:53:20 +00:00
return {
nickname: "",
role: 2
};
2023-10-04 17:26:47 +00:00
}
}
export {
useClientInfos
};