ADD:api-refresh
This commit is contained in:
parent
3c86933dee
commit
c557c383e3
6 changed files with 28 additions and 9 deletions
|
|
@ -1 +1 @@
|
||||||
{"id":"dev","timestamp":1768447040644}
|
{"id":"dev","timestamp":1768447757574}
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"id":"dev","timestamp":1768447040644,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
{"id":"dev","timestamp":1768447757574,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"date": "2026-01-15T03:17:28.679Z",
|
"date": "2026-01-15T03:29:24.697Z",
|
||||||
"preset": "nitro-dev",
|
"preset": "nitro-dev",
|
||||||
"framework": {
|
"framework": {
|
||||||
"name": "nuxt",
|
"name": "nuxt",
|
||||||
|
|
@ -9,9 +9,9 @@
|
||||||
"nitro": "2.12.8"
|
"nitro": "2.12.8"
|
||||||
},
|
},
|
||||||
"dev": {
|
"dev": {
|
||||||
"pid": 28528,
|
"pid": 15120,
|
||||||
"workerAddress": {
|
"workerAddress": {
|
||||||
"socketPath": "\\\\.\\pipe\\nitro-worker-28528-1-1-6605.sock"
|
"socketPath": "\\\\.\\pipe\\nitro-worker-15120-1-1-7719.sock"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
4
Frontend-Learner/.nuxt/nuxt.d.ts
vendored
4
Frontend-Learner/.nuxt/nuxt.d.ts
vendored
|
|
@ -1,8 +1,8 @@
|
||||||
/// <reference types="quasar" />
|
/// <reference types="quasar" />
|
||||||
/// <reference types="@nuxtjs/tailwindcss" />
|
|
||||||
/// <reference types="@nuxt/telemetry" />
|
|
||||||
/// <reference types="nuxt-quasar-ui" />
|
/// <reference types="nuxt-quasar-ui" />
|
||||||
/// <reference types="@nuxt/devtools" />
|
/// <reference types="@nuxt/devtools" />
|
||||||
|
/// <reference types="@nuxtjs/tailwindcss" />
|
||||||
|
/// <reference types="@nuxt/telemetry" />
|
||||||
/// <reference path="types/builder-env.d.ts" />
|
/// <reference path="types/builder-env.d.ts" />
|
||||||
/// <reference types="nuxt" />
|
/// <reference types="nuxt" />
|
||||||
/// <reference path="types/app-defaults.d.ts" />
|
/// <reference path="types/app-defaults.d.ts" />
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// generated by the @nuxtjs/tailwindcss <https://github.com/nuxt-modules/tailwindcss> module at 15/1/2569 10:17:22
|
// generated by the @nuxtjs/tailwindcss <https://github.com/nuxt-modules/tailwindcss> module at 15/1/2569 10:29:18
|
||||||
import "@nuxtjs/tailwindcss/config-ctx"
|
import "@nuxtjs/tailwindcss/config-ctx"
|
||||||
import configMerger from "@nuxtjs/tailwindcss/merger";
|
import configMerger from "@nuxtjs/tailwindcss/merger";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,25 @@ export const useAuth = () => {
|
||||||
|
|
||||||
if (error.value) {
|
if (error.value) {
|
||||||
if (error.value.statusCode === 401) {
|
if (error.value.statusCode === 401) {
|
||||||
logout()
|
// Try to refresh token
|
||||||
|
const refreshed = await refreshAccessToken()
|
||||||
|
if (refreshed) {
|
||||||
|
// Retry fetch with new token
|
||||||
|
const { data: retryData, error: retryError } = await useFetch<User>(`${API_BASE_URL}/user/me`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token.value}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (retryData.value) {
|
||||||
|
user.value = retryData.value
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (retryError.value) throw retryError.value
|
||||||
|
} else {
|
||||||
|
logout()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw error.value
|
throw error.value
|
||||||
}
|
}
|
||||||
|
|
@ -239,6 +257,7 @@ export const useAuth = () => {
|
||||||
fetchUserProfile,
|
fetchUserProfile,
|
||||||
requestPasswordReset,
|
requestPasswordReset,
|
||||||
confirmResetPassword,
|
confirmResetPassword,
|
||||||
|
refreshAccessToken,
|
||||||
logout
|
logout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue