Skip to content

Commit d975989

Browse files
fix(#984): allow custom endpoint subpaths for authjs (#986)
Co-authored-by: Zoey <zoeykaiser8@gmail.com>
1 parent 0d3181c commit d975989

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/runtime/server/services/authjs/nuxtAuthHandler.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ let usedSecret: string | undefined
2424
/** Setup the nuxt (next) auth event handler, based on the passed in options */
2525
export function NuxtAuthHandler(nuxtAuthOptions?: AuthOptions) {
2626
const isProduction = process.env.NODE_ENV === 'production'
27-
const trustHostUserPreference = useTypedBackendConfig(useRuntimeConfig(), 'authjs').trustHost
27+
const runtimeConfig = useRuntimeConfig()
28+
const trustHostUserPreference = useTypedBackendConfig(runtimeConfig, 'authjs').trustHost
2829

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

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

5152
// Uncomment to enable framework-author specific functionality
5253
// raw: raw as typeof raw
@@ -134,7 +135,7 @@ export async function getServerSession(event: H3Event) {
134135
cookies: parseCookies(event),
135136
providerId: undefined,
136137
error: undefined,
137-
host: sessionUrl.origin,
138+
host: sessionUrl.href,
138139
query: Object.fromEntries(sessionUrl.searchParams)
139140
}
140141

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

0 commit comments

Comments
 (0)