Skip to content

Commit

Permalink
fix: weird route bug, possible regression
Browse files Browse the repository at this point in the history
  • Loading branch information
qin-guan committed Sep 22, 2023
1 parent 20f0a3c commit 180ac4e
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 171 deletions.
14 changes: 8 additions & 6 deletions composables/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ export const $api = $fetch.create({
},
})

export function useApiFetch<T>(url: string, options: UseFetchOptions<T> = {}) {
const defaults: UseFetchOptions<T> = {
type ApiFetchRequest<T> = Ref<T> | T | (() => T)

export function useApiFetch<ReqT extends string, ResT>(request: ApiFetchRequest<ReqT>, options: UseFetchOptions<ResT> = {}) {
const defaults: UseFetchOptions<ResT> = {
$fetch: $api,
}
const params = defu(options, defaults)
return useFetch(url, params)
return useFetch(request, params)
}

export function useLazyApiFetch<T>(url: string, options: UseFetchOptions<T> = {}) {
const defaults: UseFetchOptions<T> = {
export function useLazyApiFetch<ReqT extends string, ResT>(request: ApiFetchRequest<ReqT>, options: Omit<UseFetchOptions<ResT>, 'lazy'> = {}) {
const defaults: UseFetchOptions<ResT> = {
$fetch: $api,
}
const params = defu(options, defaults)
return useLazyFetch(url, params)
return useLazyFetch(request, params)
}
2 changes: 1 addition & 1 deletion composables/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function useUser() {
const auth = useCurrentUser()
return useApiFetch('/api/user/abc', { immediate: false, watch: [() => auth.value?.uid] })
return useApiFetch(() => `/api/user/${auth.value?.uid}`, { immediate: false, watch: [() => auth.value?.uid] })
}
Loading

0 comments on commit 180ac4e

Please # to comment.