Skip to content

Commit 180ac4e

Browse files
committed
fix: weird route bug, possible regression
1 parent 20f0a3c commit 180ac4e

File tree

4 files changed

+169
-171
lines changed

4 files changed

+169
-171
lines changed

composables/fetch.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ export const $api = $fetch.create({
1313
},
1414
})
1515

16-
export function useApiFetch<T>(url: string, options: UseFetchOptions<T> = {}) {
17-
const defaults: UseFetchOptions<T> = {
16+
type ApiFetchRequest<T> = Ref<T> | T | (() => T)
17+
18+
export function useApiFetch<ReqT extends string, ResT>(request: ApiFetchRequest<ReqT>, options: UseFetchOptions<ResT> = {}) {
19+
const defaults: UseFetchOptions<ResT> = {
1820
$fetch: $api,
1921
}
2022
const params = defu(options, defaults)
21-
return useFetch(url, params)
23+
return useFetch(request, params)
2224
}
2325

24-
export function useLazyApiFetch<T>(url: string, options: UseFetchOptions<T> = {}) {
25-
const defaults: UseFetchOptions<T> = {
26+
export function useLazyApiFetch<ReqT extends string, ResT>(request: ApiFetchRequest<ReqT>, options: Omit<UseFetchOptions<ResT>, 'lazy'> = {}) {
27+
const defaults: UseFetchOptions<ResT> = {
2628
$fetch: $api,
2729
}
2830
const params = defu(options, defaults)
29-
return useLazyFetch(url, params)
31+
return useLazyFetch(request, params)
3032
}

composables/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export function useUser() {
22
const auth = useCurrentUser()
3-
return useApiFetch('/api/user/abc', { immediate: false, watch: [() => auth.value?.uid] })
3+
return useApiFetch(() => `/api/user/${auth.value?.uid}`, { immediate: false, watch: [() => auth.value?.uid] })
44
}

0 commit comments

Comments
 (0)