Skip to content

Commit

Permalink
fix(core): support trailingSlash in providerAndAccountId parsing (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed Apr 29, 2024
1 parent 42ecf79 commit 46f9582
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/lib/utils/web.ts
Expand Up @@ -123,9 +123,9 @@ export function parseActionAndProviderId(

if (a === null) throw new UnknownAction(`Cannot parse action at ${pathname}`)

const [_, actionAndProviderId] = a
const actionAndProviderId = a.at(-1)!

const b = actionAndProviderId.replace(/^\//, "").split("/")
const b = actionAndProviderId.replace(/^\//, "").split("/").filter(Boolean)

if (b.length !== 1 && b.length !== 2)
throw new UnknownAction(`Cannot parse action at ${pathname}`)
Expand Down
18 changes: 18 additions & 0 deletions packages/core/test/url-parsing.test.ts
Expand Up @@ -30,6 +30,12 @@ describe("parse the action and provider id", () => {
error: "Cannot parse action at /api/auth/signinn/github",
basePath: "/api/auth",
},
{
path: "/api/auth/signin/github/",
action: "signin",
providerId: "github",
basePath: "/api/auth",
},
{
path: "/api/auth/signin/github",
action: "signin",
Expand All @@ -46,6 +52,18 @@ describe("parse the action and provider id", () => {
error: "Cannot parse action at /api/auth/signin/api/auth/signin/github",
basePath: "/api/auth",
},
{
path: "/auth/signin/auth0/",
action: "signin",
providerId: "auth0",
basePath: "/auth",
},
{
path: "/auth/signin/auth0///",
action: "signin",
providerId: "auth0",
basePath: "/auth",
},
{
path: "/auth/signin/auth0",
action: "signin",
Expand Down

0 comments on commit 46f9582

Please sign in to comment.