From 38ce7c535ffec6c0bee3cfe43c095975e5300c23 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Thu, 23 Nov 2023 11:39:58 +0000 Subject: [PATCH] fix: import nuxt composables from #imports (#562) --- docs/content/3.application-side/4.protecting-pages.md | 3 ++- docs/content/v0.5/3.application-side/4.protecting-pages.md | 3 ++- src/runtime/composables/authjs/useAuth.ts | 4 ++-- src/runtime/composables/commonAuthState.ts | 3 +-- src/runtime/composables/local/useAuth.ts | 2 +- src/runtime/composables/local/useAuthState.ts | 2 +- src/runtime/middleware/auth.ts | 3 +-- src/runtime/plugin.ts | 3 +-- src/runtime/utils/callWithNuxt.ts | 4 ++-- src/runtime/utils/fetch.ts | 2 +- src/runtime/utils/url.ts | 3 +-- 11 files changed, 15 insertions(+), 17 deletions(-) diff --git a/docs/content/3.application-side/4.protecting-pages.md b/docs/content/3.application-side/4.protecting-pages.md index 750f40cd..8930b37b 100644 --- a/docs/content/3.application-side/4.protecting-pages.md +++ b/docs/content/3.application-side/4.protecting-pages.md @@ -131,7 +131,8 @@ export default defineNuxtRouteMiddleware((to) => { ``` ```ts [callWithNuxt] // file: ~/middleware/authentication.global.ts -import { callWithNuxt, useNuxtApp } from '#app' +import { useNuxtApp } from '#imports' +import { callWithNuxt } from '#app/nuxt' export default defineNuxtRouteMiddleware((to) => { // It's important to do this as early as possible diff --git a/docs/content/v0.5/3.application-side/4.protecting-pages.md b/docs/content/v0.5/3.application-side/4.protecting-pages.md index fd436567..f8e5128c 100644 --- a/docs/content/v0.5/3.application-side/4.protecting-pages.md +++ b/docs/content/v0.5/3.application-side/4.protecting-pages.md @@ -117,7 +117,8 @@ export default defineNuxtRouteMiddleware((to) => { ``` ```ts [callWithNuxt] // file: ~/middleware/authentication.global.ts -import { callWithNuxt, useNuxtApp } from '#app' +import { useNuxtApp } from '#imports' +import { callWithNuxt } from '#app/nuxt' export default defineNuxtRouteMiddleware((to) => { // It's important to do this as early as possible diff --git a/src/runtime/composables/authjs/useAuth.ts b/src/runtime/composables/authjs/useAuth.ts index 15981b14..e8a2ae0b 100644 --- a/src/runtime/composables/authjs/useAuth.ts +++ b/src/runtime/composables/authjs/useAuth.ts @@ -2,8 +2,8 @@ import type { AppProvider, BuiltInProviderType } from 'next-auth/providers' import { defu } from 'defu' import { readonly, Ref } from 'vue' import { appendHeader } from 'h3' -import { callWithNuxt } from '#app' -import type { NuxtApp } from '#app' +import { callWithNuxt } from '#app/nuxt' +import type { NuxtApp } from '#app/nuxt' import { determineCallbackUrl } from '../../utils/url' import { makeCWN, joinPathToApiURLWN, navigateToAuthPageWN, getRequestURLWN } from '../../utils/callWithNuxt' import { _fetch } from '../../utils/fetch' diff --git a/src/runtime/composables/commonAuthState.ts b/src/runtime/composables/commonAuthState.ts index f50292f3..a4654a42 100644 --- a/src/runtime/composables/commonAuthState.ts +++ b/src/runtime/composables/commonAuthState.ts @@ -1,9 +1,8 @@ import { computed } from 'vue' import getURL from 'requrl' import { joinURL } from 'ufo' -import { useRuntimeConfig, useRequestEvent } from '#app' import { SessionLastRefreshedAt, SessionStatus } from '../types' -import { useState } from '#imports' +import { useRuntimeConfig, useRequestEvent, useState } from '#imports' export const makeCommonAuthState = () => { const data = useState('auth:data', () => undefined) diff --git a/src/runtime/composables/local/useAuth.ts b/src/runtime/composables/local/useAuth.ts index e01bd740..e9127d3a 100644 --- a/src/runtime/composables/local/useAuth.ts +++ b/src/runtime/composables/local/useAuth.ts @@ -1,5 +1,5 @@ import { readonly, Ref } from 'vue' -import { callWithNuxt } from '#app' +import { callWithNuxt } from '#app/nuxt' import { CommonUseAuthReturn, SignOutFunc, SignInFunc, GetSessionFunc, SecondarySignInOptions } from '../../types' import { _fetch } from '../../utils/fetch' import { jsonPointerGet, useTypedBackendConfig } from '../../helpers' diff --git a/src/runtime/composables/local/useAuthState.ts b/src/runtime/composables/local/useAuthState.ts index b12f6b6d..bc634f07 100644 --- a/src/runtime/composables/local/useAuthState.ts +++ b/src/runtime/composables/local/useAuthState.ts @@ -1,5 +1,5 @@ import { computed, watch, ComputedRef } from 'vue' -import { CookieRef } from '#app' +import type { CookieRef } from '#app' import { CommonUseAuthStateReturn } from '../../types' import { makeCommonAuthState } from '../commonAuthState' import { useTypedBackendConfig } from '../../helpers' diff --git a/src/runtime/middleware/auth.ts b/src/runtime/middleware/auth.ts index e594b3ce..d23d48b8 100644 --- a/src/runtime/middleware/auth.ts +++ b/src/runtime/middleware/auth.ts @@ -1,6 +1,5 @@ -import { navigateTo, defineNuxtRouteMiddleware, useRuntimeConfig } from '#app' import { navigateToAuthPages, determineCallbackUrl } from '../utils/url' -import { useAuth } from '#imports' +import { navigateTo, defineNuxtRouteMiddleware, useRuntimeConfig, useAuth } from '#imports' type MiddlewareMeta = boolean | { /** Whether to only allow unauthenticated users to access this page. diff --git a/src/runtime/plugin.ts b/src/runtime/plugin.ts index 2acca240..db926f6e 100644 --- a/src/runtime/plugin.ts +++ b/src/runtime/plugin.ts @@ -1,7 +1,6 @@ -import { addRouteMiddleware, defineNuxtPlugin, useRuntimeConfig } from '#app' import { getHeader } from 'h3' import authMiddleware from './middleware/auth' -import { useAuth, useAuthState } from '#imports' +import { addRouteMiddleware, defineNuxtPlugin, useRuntimeConfig, useAuth, useAuthState } from '#imports' export default defineNuxtPlugin(async (nuxtApp) => { // 1. Initialize authentication state, potentially fetch current session diff --git a/src/runtime/utils/callWithNuxt.ts b/src/runtime/utils/callWithNuxt.ts index 1c80c746..97f23b39 100644 --- a/src/runtime/utils/callWithNuxt.ts +++ b/src/runtime/utils/callWithNuxt.ts @@ -1,5 +1,5 @@ -import type { NuxtApp } from '#app' -import { callWithNuxt } from '#app' +import type { NuxtApp } from '#app/nuxt' +import { callWithNuxt } from '#app/nuxt' import { getRequestURL, joinPathToApiURL, navigateToAuthPages } from './url' export const navigateToAuthPageWN = (nuxt: NuxtApp, href: string) => callWithNuxt(nuxt, navigateToAuthPages, [href]) diff --git a/src/runtime/utils/fetch.ts b/src/runtime/utils/fetch.ts index 7b4ac108..bae05814 100644 --- a/src/runtime/utils/fetch.ts +++ b/src/runtime/utils/fetch.ts @@ -1,4 +1,4 @@ -import { callWithNuxt } from '#app' +import { callWithNuxt } from '#app/nuxt' import { joinPathToApiURL } from './url' import { useNuxtApp } from '#imports' diff --git a/src/runtime/utils/url.ts b/src/runtime/utils/url.ts index 2d2cae44..41ee7660 100644 --- a/src/runtime/utils/url.ts +++ b/src/runtime/utils/url.ts @@ -1,8 +1,7 @@ import { joinURL } from 'ufo' import getURL from 'requrl' import { sendRedirect } from 'h3' -import { useRequestEvent, useNuxtApp, abortNavigation } from '#app' -import { useAuthState, useRuntimeConfig } from '#imports' +import { useRequestEvent, useNuxtApp, abortNavigation, useAuthState, useRuntimeConfig } from '#imports' export const getRequestURL = (includePath = true) => getURL(useRequestEvent()?.node.req, includePath) export const joinPathToApiURL = (path: string) => joinURL(useAuthState()._internal.baseURL, path)