Skip to content

Commit e48ffa6

Browse files
BilalG1N2D4
andauthored
return to options (#898)
<!-- Make sure you've read the CONTRIBUTING.md guidelines: https://github.com/stack-auth/stack-auth/blob/dev/CONTRIBUTING.md --> <!-- RECURSEML_SUMMARY:START --> ## High-level PR Summary This PR adds an optional `returnTo` parameter to the `signInWithOAuth` function in the Stack Auth SDK. This allows developers to specify a custom redirect URL after OAuth authentication instead of always using the default OAuth callback URL. The change updates both the interface definition and the implementation to support this new optional parameter. ⏱️ Estimated Review Time: 0h 15m <details> <summary>💡 Review Order Suggestion</summary> | Order | File Path | |-------|-----------| | 1 | `packages/template/src/lib/stack-app/apps/interfaces/client-app.ts` | | 2 | `packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts` | </details> <!-- RECURSEML_SUMMARY:END --> <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Add optional `returnTo` parameter to `signInWithOAuth` for custom redirect URLs in `client-app-impl.ts` and update interface in `client-app.ts`. > > - **Behavior**: > - `signInWithOAuth` in `client-app-impl.ts` now accepts an optional `options` parameter with `returnTo` for custom redirect URLs. > - Default redirect URL is `this.urls.oauthCallback` if `returnTo` is not provided. > - **Interfaces**: > - Updated `signInWithOAuth` signature in `client-app.ts` to include optional `options` parameter with `returnTo`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=stack-auth%2Fstack-auth&utm_source=github&utm_medium=referral)<sup> for eb748cb. You can [customize](https://app.ellipsis.dev/stack-auth/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN --> <!-- RECURSEML_ANALYSIS:START --> ## Review by RecurseML _🔍 Review performed on [2d2a6d7..eb748cb](2d2a6d7...eb748cbe7775eaba8d261d014951c4140d4bfe5c)_ ✨ No bugs found, your code is sparkling clean <details> <summary>✅ Files analyzed, no issues (2)</summary> • `packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts` • `packages/template/src/lib/stack-app/apps/interfaces/client-app.ts` </details> [![Need help? Join our Discord](https://img.shields.io/badge/Need%20help%3F%20Join%20our%20Discord-5865F2?style=plastic&logo=discord&logoColor=white)](https://discord.gg/n3SsVDAW6U) <!-- RECURSEML_ANALYSIS:END --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * signInWithOAuth now accepts an optional options parameter with returnTo, allowing apps to override the post-login redirect URL. * Defaults remain unchanged; if returnTo isn’t provided, the existing OAuth callback is used. * Backwards compatible: existing calls without options continue to work. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
1 parent 23b9eb8 commit e48ffa6

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

packages/template/src/lib/stack-app/apps/implementations/client-app-impl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ export class _StackClientAppImplIncomplete<HasTokenStore extends boolean, Projec
15971597
return res;
15981598
}
15991599

1600-
async signInWithOAuth(provider: ProviderType) {
1600+
async signInWithOAuth(provider: ProviderType, options?: { returnTo?: string }) {
16011601
if (typeof window === "undefined") {
16021602
throw new Error("signInWithOAuth can currently only be called in a browser environment");
16031603
}
@@ -1608,7 +1608,7 @@ export class _StackClientAppImplIncomplete<HasTokenStore extends boolean, Projec
16081608
this._interface,
16091609
{
16101610
provider,
1611-
redirectUrl: this.urls.oauthCallback,
1611+
redirectUrl: options?.returnTo ?? this.urls.oauthCallback,
16121612
errorRedirectUrl: this.urls.error,
16131613
providerScope: this._oauthScopesOnSignIn[provider]?.join(" "),
16141614
},

packages/template/src/lib/stack-app/apps/interfaces/client-app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export type StackClientApp<HasTokenStore extends boolean = boolean, ProjectId ex
3838

3939
readonly urls: Readonly<HandlerUrls>,
4040

41-
signInWithOAuth(provider: string): Promise<void>,
41+
signInWithOAuth(provider: string, options?: { returnTo?: string }): Promise<void>,
4242
signInWithCredential(options: { email: string, password: string, noRedirect?: boolean }): Promise<Result<undefined, KnownErrors["EmailPasswordMismatch"] | KnownErrors["InvalidTotpCode"]>>,
4343
signUpWithCredential(options: { email: string, password: string, noRedirect?: boolean, verificationCallbackUrl?: string }): Promise<Result<undefined, KnownErrors["UserWithEmailAlreadyExists"] | KnownErrors["PasswordRequirementsNotMet"]>>,
4444
signInWithPasskey(): Promise<Result<undefined, KnownErrors["PasskeyAuthenticationFailed"]| KnownErrors["InvalidTotpCode"] | KnownErrors["PasskeyWebAuthnError"]>>,

0 commit comments

Comments
 (0)