From 3298e7aec4e320b55c3f9e90873ddcd562c91f23 Mon Sep 17 00:00:00 2001 From: Basile Vernouillet Date: Wed, 8 Jul 2026 18:18:22 +0200 Subject: [PATCH] feat(sdk-generator): make OAuth2 redirectUrl optional Matches PocketBase v0.39.4 which dropped the required redirectURL validator from authWithOAuth2Code(). Closes #63. Co-Authored-By: Claude Opus 4.8 (1M context) --- .changeset/oauth2-redirect-optional.md | 5 +++++ packages/pbkit/src/sdk-generator/generate.ts | 2 +- .../pbkit/src/test/__snapshots__/sdk-generator.test.ts.snap | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/oauth2-redirect-optional.md diff --git a/.changeset/oauth2-redirect-optional.md b/.changeset/oauth2-redirect-optional.md new file mode 100644 index 0000000..5f0916f --- /dev/null +++ b/.changeset/oauth2-redirect-optional.md @@ -0,0 +1,5 @@ +--- +"@karnak19/pbkit": patch +--- + +Make `redirectUrl` optional in generated `auth*WithOAuth2` functions, matching PocketBase v0.39.4 which dropped the required `redirectURL` validator from `authWithOAuth2Code()`. diff --git a/packages/pbkit/src/sdk-generator/generate.ts b/packages/pbkit/src/sdk-generator/generate.ts index d5f8799..c201708 100644 --- a/packages/pbkit/src/sdk-generator/generate.ts +++ b/packages/pbkit/src/sdk-generator/generate.ts @@ -164,7 +164,7 @@ function authFunctions(col: CollectionSchema): string[] { lines.push("}"); lines.push(""); lines.push( - `export async function auth${s}WithOAuth2(provider: string, code: string, codeVerifier: string, redirectUrl: string, opts?: { client?: PbClient }): Promise<${p}Record> {`, + `export async function auth${s}WithOAuth2(provider: string, code: string, codeVerifier: string, redirectUrl = "", opts?: { client?: PbClient }): Promise<${p}Record> {`, ); lines.push(" const pb = opts?.client ?? client"); lines.push( diff --git a/packages/pbkit/src/test/__snapshots__/sdk-generator.test.ts.snap b/packages/pbkit/src/test/__snapshots__/sdk-generator.test.ts.snap index 78546ea..5588fa7 100644 --- a/packages/pbkit/src/test/__snapshots__/sdk-generator.test.ts.snap +++ b/packages/pbkit/src/test/__snapshots__/sdk-generator.test.ts.snap @@ -62,7 +62,7 @@ export async function authUserWithPassword(usernameOrEmail: string, password: st return result.record as unknown as UsersRecord } -export async function authUserWithOAuth2(provider: string, code: string, codeVerifier: string, redirectUrl: string, opts?: { client?: PbClient }): Promise { +export async function authUserWithOAuth2(provider: string, code: string, codeVerifier: string, redirectUrl = "", opts?: { client?: PbClient }): Promise { const pb = opts?.client ?? client const result = await pb.collection("users").authWithOAuth2Code(provider, code, codeVerifier, redirectUrl) return result.record as unknown as UsersRecord