Skip to content

Commit

Permalink
fix(#984): allow custom endpoint subpaths for authjs
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix-ru committed Jan 16, 2025
1 parent 52d4b9a commit 7db67a9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/runtime/server/services/authjs/nuxtAuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ let usedSecret: string | undefined
/** Setup the nuxt (next) auth event handler, based on the passed in options */
export function NuxtAuthHandler(nuxtAuthOptions?: AuthOptions) {
const isProduction = process.env.NODE_ENV === 'production'
const trustHostUserPreference = useTypedBackendConfig(useRuntimeConfig(), 'authjs').trustHost
const runtimeConfig = useRuntimeConfig()
const trustHostUserPreference = useTypedBackendConfig(runtimeConfig, 'authjs').trustHost

usedSecret = nuxtAuthOptions?.secret
if (!usedSecret) {
Expand All @@ -46,7 +47,7 @@ export function NuxtAuthHandler(nuxtAuthOptions?: AuthOptions) {
trustHost: true,

// AuthJS uses `/auth` as default, but we rely on `/api/auth` (same as in previous `next-auth`)
basePath: '/api/auth'
basePath: runtimeConfig.public.auth.baseURL,

// Uncomment to enable framework-author specific functionality
// raw: raw as typeof raw
Expand Down Expand Up @@ -134,7 +135,7 @@ export async function getServerSession(event: H3Event) {
cookies: parseCookies(event),
providerId: undefined,
error: undefined,
host: sessionUrl.origin,
host: sessionUrl.href,
query: Object.fromEntries(sessionUrl.searchParams)
}

Expand Down Expand Up @@ -183,7 +184,7 @@ export function getToken<R extends boolean = false>({ event, secureCookie, secre
*/
async function createRequestForAuthjs(event: H3Event, trustHostUserPreference: boolean): Promise<RequestInternal> {
const nextRequest: Omit<RequestInternal, 'action'> = {
host: getRequestURLFromH3Event(event, trustHostUserPreference).origin,
host: getRequestURLFromH3Event(event, trustHostUserPreference).href,
body: undefined,
cookies: parseCookies(event),
query: undefined,
Expand Down

0 comments on commit 7db67a9

Please sign in to comment.