@vesperjs/nuxt 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,7 +19,7 @@ export const useMutationApi = async function <T = unknown, E = any>(
19
19
  url: string,
20
20
  { method, body = {}, token = null, onRequestError, onResponseError }: MutationAPIOptions,
21
21
  ): Promise<{
22
- token: string | undefined
22
+ token: string | null | undefined
23
23
  data: T | undefined
24
24
  error: FetchError<E> | undefined
25
25
  pending: boolean
@@ -29,11 +29,10 @@ export const useMutationApi = async function <T = unknown, E = any>(
29
29
 
30
30
  const headers: Record<string, string> = commonHeaders.value
31
31
 
32
- const tokenRef = ref<string>()
32
+ const tokenRef = ref<string | null>()
33
33
 
34
34
  if (token) {
35
35
  headers.Authorization = `Bearer ${token}`
36
- tokenRef.value = token
37
36
  }
38
37
 
39
38
  const options: FetchOptions<'json'> = {
@@ -52,10 +51,10 @@ export const useMutationApi = async function <T = unknown, E = any>(
52
51
 
53
52
  if (method == 'post' || method == 'put') {
54
53
  options.body = body
55
- options.onResponse = ({ response }: { response: FetchResponse<T> }) => {
56
- if ((method == 'post' && !tokenRef.value) || method == 'put')
57
- tokenRef.value = response.headers.get('Authorization')?.split(' ')[1]
58
- }
54
+ }
55
+
56
+ options.onResponse = ({ response }: { response: FetchResponse<T> }) => {
57
+ tokenRef.value = response.headers.get('Authorization')?.split(' ')[1] ?? token
59
58
  }
60
59
 
61
60
  const { data, error, pending } = await useOFetch<T, E>(url, options)
@@ -37,7 +37,7 @@ export const useQueryApi = async function <T = unknown, E = any>(
37
37
 
38
38
  const key = options?.key ?? url
39
39
 
40
- const tokenRef = ref<string>()
40
+ const tokenRef = ref<string | null>()
41
41
 
42
42
  const headers: Record<string, string> = commonHeaders.value
43
43
 
@@ -46,7 +46,6 @@ export const useQueryApi = async function <T = unknown, E = any>(
46
46
 
47
47
  if (options?.token) {
48
48
  headers.Authorization = `Bearer ${options.token}`
49
- tokenRef.value = options.token
50
49
  }
51
50
 
52
51
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -56,7 +55,7 @@ export const useQueryApi = async function <T = unknown, E = any>(
56
55
  query: options?.query ?? {},
57
56
  headers,
58
57
  onResponse({ response }: { response: FetchResponse<T> }) {
59
- if (!tokenRef.value) tokenRef.value = response.headers.get('Authorization')?.split(' ')[1]
58
+ tokenRef.value = response.headers.get('Authorization')?.split(' ')[1] ?? options?.token
60
59
  },
61
60
  }
62
61
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesperjs/nuxt",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "keywords": [
5
5
  "nuxt",
6
6
  "vue.js"
@@ -24,13 +24,16 @@
24
24
  "@nuxt/eslint": "latest",
25
25
  "@nuxtjs/i18n": "^10.2.4",
26
26
  "@types/node": "^24.12.2",
27
- "@vesperjs/shared": "0.2.1",
27
+ "@vesperjs/shared": "0.3.0",
28
28
  "eslint": "^10.2.0",
29
+ "eslint-typegen": "2.3.1",
29
30
  "nuxt": "^4.3.1",
30
31
  "ofetch": "^1.5.1",
31
32
  "oxfmt": "^0.44.0",
32
- "typescript": "^6.0.2",
33
- "vue": "^3.6.0-beta.9"
33
+ "typescript": "^6.0.2"
34
+ },
35
+ "peerDependencies": {
36
+ "vue": "^3.5.32 || ^3.6.0-beta.9"
34
37
  },
35
38
  "scripts": {
36
39
  "dev": "nuxi dev .playground",