Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use startsWith() instead of exact match comparison #1856

Open
wants to merge 2 commits into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/server/auth-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ ca/T0LLtgmbMmxSv/MmzIg==
authClient.handleLogin = vi.fn()
await authClient.handler(request)
expect(authClient.handleLogin).toHaveBeenCalled()

// Also checks if the path is /auth/login/ (with trailing slash)
const request2 = new NextRequest("https://example.com/auth/login/", {
method: "GET",
})
await authClient.handler(request2)
expect(authClient.handleLogin).toHaveBeenCalled()
})

it("should call the callback handler if the path is /auth/callback", async () => {
Expand Down
12 changes: 6 additions & 6 deletions src/server/auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,19 @@ export class AuthClient {
const { pathname } = req.nextUrl
const method = req.method

if (method === "GET" && pathname === this.routes.login) {
if (method === "GET" && pathname.startsWith(this.routes.login)) {
return this.handleLogin(req)
} else if (method === "GET" && pathname === this.routes.logout) {
} else if (method === "GET" && pathname.startsWith(this.routes.logout)) {
return this.handleLogout(req)
} else if (method === "GET" && pathname === this.routes.callback) {
} else if (method === "GET" && pathname.startsWith(this.routes.callback)) {
return this.handleCallback(req)
} else if (method === "GET" && pathname === this.routes.profile) {
} else if (method === "GET" && pathname.startsWith(this.routes.profile)) {
return this.handleProfile(req)
} else if (method === "GET" && pathname === this.routes.accessToken) {
} else if (method === "GET" && pathname.startsWith(this.routes.accessToken)) {
return this.handleAccessToken(req)
} else if (
method === "POST" &&
pathname === this.routes.backChannelLogout
pathname.startsWith(this.routes.backChannelLogout)
) {
return this.handleBackChannelLogout(req)
} else {
Expand Down