Skip to content

Commit

Permalink
fix: import nuxt composables from #imports (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Nov 23, 2023
1 parent 4b4b7f0 commit 38ce7c5
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 17 deletions.
3 changes: 2 additions & 1 deletion docs/content/3.application-side/4.protecting-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docs/content/v0.5/3.application-side/4.protecting-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/composables/authjs/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/composables/commonAuthState.ts
Original file line number Diff line number Diff line change
@@ -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 = <SessionData>() => {
const data = useState<SessionData | undefined | null>('auth:data', () => undefined)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/local/useAuth.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/local/useAuthState.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/middleware/auth.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/utils/callWithNuxt.ts
Original file line number Diff line number Diff line change
@@ -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])
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/utils/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { callWithNuxt } from '#app'
import { callWithNuxt } from '#app/nuxt'
import { joinPathToApiURL } from './url'
import { useNuxtApp } from '#imports'

Expand Down
3 changes: 1 addition & 2 deletions src/runtime/utils/url.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 38ce7c5

Please sign in to comment.