
const KEY_TOKEN = 'KEY_TOKEN'
const KEY_USER = 'KEY_USER'


function setToken(token: string) {
    localStorage.setItem(KEY_TOKEN, token)
}

function getToken(): string | null {
    return localStorage.getItem(KEY_TOKEN)
}



function clearToken(){
    localStorage.removeItem(KEY_TOKEN)
}
export const token = {
    setToken,
    getToken,
    clearToken
}

function setUserMsg(user: object) {
    localStorage.setItem(KEY_USER, JSON.stringify(user))
}



function getUserMsg(): object | null {
    let userStr;
    try{
        userStr = localStorage.getItem(KEY_USER) 
    }catch(err){
        console.log(err,'123khi12oi3h12io3oi123io2j13oij12io3');  
    }
   
    return  userStr? JSON.parse(userStr) :''
}

function clearUserMsg(){
    localStorage.removeItem(KEY_USER)
}

function updateUserMsg(data: object){
    const userInfo = getUserMsg()
    const newData = Object.assign(userInfo,data)
    setUserMsg(newData)
}
export const userMsg = {
    setUserMsg,
    getUserMsg,
    clearUserMsg,
    updateUserMsg
}