From feb253694536ab40d9406d1323afd1834a0e2f2c Mon Sep 17 00:00:00 2001 From: Branislav Hozza Date: Mon, 25 Mar 2024 21:02:35 +0100 Subject: [PATCH] :sparkles: refresh mechanism --- components/layout/NavigationComponent.vue | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/components/layout/NavigationComponent.vue b/components/layout/NavigationComponent.vue index 65b78e0..4be2920 100644 --- a/components/layout/NavigationComponent.vue +++ b/components/layout/NavigationComponent.vue @@ -21,8 +21,19 @@ const accountStore = useAccountStore(); const account = computed(() => accountStore.account); onMounted(async () => { - const accounts = await $web3?.eth.getAccounts(); - accountStore.setAccount(accounts?.[0] ?? null); + if (account.value) { + logger.info('Account connected:', account); + } + + logger.info('Refresh tokens'); + const { accessToken, refreshToken } = await $fetch('/api/auth/refresh', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ jwt: accountStore.accessToken, refreshToken: accountStore.refreshToken }), + }); + accountStore.setToken(accessToken, refreshToken); }); const signMessage = async (message: string): Promise => {