// Simple auth utility functions // Get the auth token from local storage export const getAuthToken = () => { return localStorage.getItem('auth_token'); }; // Set the auth token in local storage export const setAuthToken = (token) => { if (token) { localStorage.setItem('auth_token', token); } }; // Remove the auth token from local storage export const removeAuthToken = () => { localStorage.removeItem('auth_token'); }; // Check if the user is authenticated export const isAuthenticated = () => { return !!getAuthToken(); }; // Simple token parser for JWT tokens export const parseToken = (token) => { if (!token) return null; try { // Split the token and get the payload part const base64Url = token.split('.')[1]; const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/'); const jsonPayload = decodeURIComponent( atob(base64) .split('') .map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)) .join('') ); return JSON.parse(jsonPayload); } catch (error) { console.error('Error parsing token:', error); return null; } }; export default { getAuthToken, setAuthToken, removeAuthToken, isAuthenticated, parseToken };