diff --git a/src/server/auth-client.test.ts b/src/server/auth-client.test.ts index d6f80b4d..99f2c875 100644 --- a/src/server/auth-client.test.ts +++ b/src/server/auth-client.test.ts @@ -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 () => { diff --git a/src/server/auth-client.ts b/src/server/auth-client.ts index bca8165e..2c85d8a2 100644 --- a/src/server/auth-client.ts +++ b/src/server/auth-client.ts @@ -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 {