DEV Community

Cover image for How to get refresh token in Vite Vue 3
alin
alin

Posted on

How to get refresh token in Vite Vue 3

<script setup>

const accessrefresh = async () => {
    axios.defaults.headers.common['Authorization'] = storeaccesstoken.accesstoken;
    await axios.create({withCredentials: true}).post("http://localhost:81/auth/refresh/")
        .then((response) => {   axios.defaults.headers.common['Authorization'] = response.data.token;
            storeaccesstoken.stateAccessToken(response.data.token);
        })
        .catch((errors) => {
            console.log("errors access refresh: ",errors);
            if(errors?.response?.data?.message==='error') {
                Swal.fire({
                title: "Error!",
                text: "Access denied!",
                icon: "error",
                confirmButtonText: "Log in please!"
              });
            }
            storeaccesstoken.stateAccessToken(null);
            storeaccesstoken.setStateUserFalse();
            router.push({ path: '/login' })
        });
};

onBeforeMount(() => {
    window.addEventListener("beforeunload",accessrefresh());
})

<script>
Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay