const JWT_TOKEN = 'token';

const useGetToken = (failedProc: () => void) => {
    const getToken = (): string => {
        const token = sessionStorage.getItem(JWT_TOKEN);
        if (!token) {
            failedProc();
            return ""
        }
        return token
    }

    return getToken
}

const useSetToken = () => {
    const setToken = (token: string) => {
        sessionStorage.setItem(JWT_TOKEN, token);
    }
    return setToken
}

const useClearToken = () => {
    const clearToken = () => {
        sessionStorage.removeItem(JWT_TOKEN);
    }
    return clearToken
}

export { useGetToken, useSetToken, useClearToken }