Skip to content
Merged
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
11 changes: 8 additions & 3 deletions packages/core/src/@types/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { z } from "zod/v4"
import type { OAuthIntegrations } from "@/oauth/index.js"
import { OAuthAccessTokenErrorResponse, OAuthAuthorizationErrorResponse } from "@/schemas.js"
import { SESSION_VERSION } from "@/actions/session/session.js"
import { SerializeOptions } from "cookie"
import { createJoseInstance } from "@/jose.js"
import { SESSION_VERSION } from "@/actions/session/session.js"
import { OAuthAccessTokenErrorResponse, OAuthAuthorizationErrorResponse } from "@/schemas.js"
import type { RoutePattern } from "@aura-stack/router"
import type { OAuthIntegrations } from "@/oauth/index.js"

/**
* Standardized user profile returned by OAuth integrations after fetching user information
Expand Down Expand Up @@ -131,6 +132,10 @@ export interface AuthConfig {
* doesn't exist, it will throw an error during the initialization of the Auth module.
*/
secret?: string
/**
* Base path for all authentication routes. Default is `/auth`.
*/
basePath?: RoutePattern
}

export interface AuthConfigInternal {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { AuthConfig } from "@/@types/index.js"

const createInternalConfig = (authConfig?: AuthConfig): RouterConfig => {
return {
basePath: "/auth",
basePath: authConfig?.basePath ?? "/auth",
onError: onErrorHandler,
context: {
oauth: createOAuthIntegrations(authConfig?.oauth),
Expand Down
23 changes: 23 additions & 0 deletions packages/core/test/instance.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, test, expect } from "vitest"
import { createAuth } from "@/index.js"

describe("createAuth", () => {
describe("add custom basePath config", () => {
const auth = createAuth({
oauth: ["github"],
basePath: "/api/v1/auth",
})

test("valid custom path for get csrfToken", async () => {
const response = await auth.handlers.GET(new Request("https://example.com/api/v1/auth/csrfToken"))
expect(response.status).toBe(200)
const data = await response.json()
expect(data).toHaveProperty("csrfToken")
})

test("invalid path for get csrfToken", async () => {
const response = await auth.handlers.GET(new Request("https://example.com/auth/csrfToken"))
expect(response.status).toBe(404)
})
})
})