Skip to content

Commit 9c56e69

Browse files
fix(core): ignore basePath if pages configuration (#10288)
* fix: pages configuration * fix: typo * chore: test custom pages config --------- Co-authored-by: Thang Vu <[email protected]>
1 parent 86c8822 commit 9c56e69

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/core/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ export async function Auth(
183183
if (error instanceof CredentialsSignin) params.set("code", error.code)
184184

185185
const pageKind = (isAuthError && error.kind) || "error"
186-
const pagePath = config.pages?.[pageKind] ?? `/${pageKind.toLowerCase()}`
187-
const url = `${internalRequest.url.origin}${config.basePath}${pagePath}?${params}`
186+
const pagePath =
187+
config.pages?.[pageKind] ?? `${config.basePath}/${pageKind.toLowerCase()}`
188+
const url = `${internalRequest.url.origin}${pagePath}?${params}`
188189

189190
if (isRedirect) return Response.json({ url })
190191
return Response.redirect(url)

packages/core/test/actions/callback.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as jose from "jose"
33
import * as o from "oauth4webapi"
44

55
import GitHub from "../../src/providers/github.js"
6+
import Credentials from "../../src/providers/credentials.js"
67

78
import { makeAuthRequest } from "../utils.js"
89

@@ -66,3 +67,21 @@ describe("assert GET callback action", () => {
6667
)
6768
})
6869
})
70+
71+
it("should redirect to the custom error page is custom error page is defined", async () => {
72+
const { response } = await makeAuthRequest({
73+
action: "callback",
74+
path: "/credentials",
75+
config: {
76+
pages: {
77+
error:'/custom/error'
78+
},
79+
providers: [Credentials],
80+
},
81+
})
82+
83+
expect(response.status).toEqual(302)
84+
expect(response.headers.get("location")).toEqual(
85+
`https://authjs.test/custom/error?error=Configuration`
86+
)
87+
})

0 commit comments

Comments
 (0)