Skip to content

Commit

Permalink
fix(#927): fix the warnings produced by Nuxt when awaiting runtime co…
Browse files Browse the repository at this point in the history
…nfig (#959)
  • Loading branch information
phoenix-ru authored Dec 12, 2024
1 parent dd77b70 commit b1db6ec
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/runtime/composables/authjs/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function getCsrfTokenWithNuxt(nuxt: NuxtApp) {
type SignInResult = void | { error: string | null, status: number, ok: boolean, url: any }
const signIn: SignInFunc<SupportedProviders, SignInResult> = async (provider, options, authorizationParams) => {
const nuxt = useNuxtApp()
const runtimeConfig = await callWithNuxt(nuxt, useRuntimeConfig)
const runtimeConfig = useRuntimeConfig()

// 1. Lead to error page if no providers are available
const configuredProviders = await getProviders()
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/composables/local/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Credentials = { username?: string, email?: string, password?: string } & Re
const signIn: SignInFunc<Credentials, any> = async (credentials, signInOptions, signInParams, signInHeaders) => {
const nuxt = useNuxtApp()

const runtimeConfig = await callWithNuxt(nuxt, useRuntimeConfig)
const runtimeConfig = useRuntimeConfig()
const config = useTypedBackendConfig(runtimeConfig, 'local')
const { path, method } = config.endpoints.signIn
const response = await _fetch<Record<string, any>>(nuxt, path, {
Expand Down Expand Up @@ -75,7 +75,7 @@ const signIn: SignInFunc<Credentials, any> = async (credentials, signInOptions,

const signOut: SignOutFunc = async (signOutOptions) => {
const nuxt = useNuxtApp()
const runtimeConfig = await callWithNuxt(nuxt, useRuntimeConfig)
const runtimeConfig = useRuntimeConfig()
const config = useTypedBackendConfig(runtimeConfig, 'local')
const { data, token, rawToken, refreshToken, rawRefreshToken }: UseAuthStateReturn = await callWithNuxt(nuxt, useAuthState)

Expand Down
16 changes: 0 additions & 16 deletions src/runtime/utils/extractFromRuntimeConfig.ts

This file was deleted.

11 changes: 8 additions & 3 deletions src/runtime/utils/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { resolveApiUrlPath } from './url'
import { ERROR_PREFIX } from './logger'
import { callWithNuxt, useRuntimeConfig } from '#app'
import type { useNuxtApp } from '#imports'
import { type useNuxtApp, useRuntimeConfig } from '#imports'
import { callWithNuxt } from '#app/nuxt'

export async function _fetch<T>(nuxt: ReturnType<typeof useNuxtApp>, path: string, fetchOptions?: Parameters<typeof $fetch>[1]): Promise<T> {
const runtimeConfig = await callWithNuxt(nuxt, useRuntimeConfig)
// This fixes https://github.com/sidebase/nuxt-auth/issues/927
const runtimeConfigOrPromise = callWithNuxt(nuxt, useRuntimeConfig)
const runtimeConfig = 'public' in runtimeConfigOrPromise
? runtimeConfigOrPromise
: await runtimeConfigOrPromise

const joinedPath = resolveApiUrlPath(path, runtimeConfig)

// Prevent callback recursion when doing internal routing
Expand Down

0 comments on commit b1db6ec

Please sign in to comment.