Skip to content

Commit fdac10e

Browse files
authored
fix(clerk-js,shared): Improve ticket and SSO types for Future APIs (#8267)
1 parent 1c5b085 commit fdac10e

File tree

5 files changed

+61
-23
lines changed

5 files changed

+61
-23
lines changed

.changeset/famous-needles-laugh.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/shared': patch
4+
---
5+
6+
Improve types for `signIn.create` and `signUp.create` methods.

packages/clerk-js/src/core/resources/SignIn.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,11 +1145,13 @@ class SignInFuture implements SignInFutureResource {
11451145
routes.actionCompleteRedirectUrl = wrappedRoutes.redirectUrl;
11461146
}
11471147

1148-
await this._create({
1149-
strategy,
1150-
...routes,
1151-
identifier,
1152-
});
1148+
if (!this.#resource.id) {
1149+
await this._create({
1150+
strategy,
1151+
...routes,
1152+
identifier,
1153+
});
1154+
}
11531155

11541156
if (strategy === 'enterprise_sso') {
11551157
await this.#resource.__internal_basePost({

packages/clerk-js/src/core/resources/SignUp.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,21 +1026,22 @@ class SignUpFuture implements SignUpFutureResource {
10261026
}
10271027

10281028
const authenticateFn = () => {
1029-
return this.#resource.__internal_basePost({
1030-
path: this.#resource.pathRoot,
1031-
body: {
1032-
strategy,
1033-
...routes,
1034-
unsafeMetadata,
1035-
legalAccepted,
1036-
oidcPrompt,
1037-
enterpriseConnectionId,
1038-
emailAddress,
1039-
captchaToken,
1040-
captchaWidgetType,
1041-
captchaError,
1042-
},
1043-
});
1029+
const body: Record<string, unknown> = {
1030+
strategy,
1031+
...routes,
1032+
unsafeMetadata,
1033+
legalAccepted,
1034+
oidcPrompt,
1035+
enterpriseConnectionId,
1036+
emailAddress,
1037+
captchaToken,
1038+
captchaWidgetType,
1039+
captchaError,
1040+
};
1041+
if (this.#resource.id) {
1042+
return this.#resource.__internal_basePatch({ path: this.#resource.pathRoot, body });
1043+
}
1044+
return this.#resource.__internal_basePost({ path: this.#resource.pathRoot, body });
10441045
};
10451046

10461047
await authenticateFn().catch(async e => {

packages/shared/src/types/signInFuture.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ClerkError } from '../errors/clerkError';
22
import type { SetActiveNavigate } from './clerk';
33
import type { PhoneCodeChannel } from './phoneCodeChannel';
44
import type { SignInFirstFactor, SignInSecondFactor, SignInStatus, UserData } from './signInCommon';
5-
import type { OAuthStrategy, PasskeyStrategy, Web3Strategy } from './strategies';
5+
import type { OAuthStrategy, PasskeyStrategy, TicketStrategy, Web3Strategy } from './strategies';
66
import type { VerificationResource } from './verification';
77
import type { Web3Provider } from './web3';
88

@@ -12,11 +12,16 @@ export interface SignInFutureCreateParams {
1212
* username, or Web3 wallet address.
1313
*/
1414
identifier?: string;
15+
/**
16+
* The user's password. Only supported if
17+
* [password](https://clerk.com/docs/guides/configure/auth-strategies/sign-up-sign-in-options#password) is enabled.
18+
*/
19+
password?: string;
1520
/**
1621
* The first factor verification strategy to use in the sign-in flow. Depends on the `identifier` value. Each
1722
* authentication identifier supports different verification strategies.
1823
*/
19-
strategy?: OAuthStrategy | 'enterprise_sso' | PasskeyStrategy;
24+
strategy?: OAuthStrategy | 'enterprise_sso' | PasskeyStrategy | TicketStrategy;
2025
/**
2126
* The full URL or path that the OAuth provider should redirect to after successful authorization on their part.
2227
*/

packages/shared/src/types/signUpFuture.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ import type { ClerkError } from '../errors/clerkError';
22
import type { SetActiveNavigate } from './clerk';
33
import type { PhoneCodeChannel } from './phoneCodeChannel';
44
import type { SignUpField, SignUpIdentificationField, SignUpStatus, SignUpVerificationResource } from './signUpCommon';
5-
import type { Web3Strategy } from './strategies';
5+
import type {
6+
AppleIdTokenStrategy,
7+
EnterpriseSSOStrategy,
8+
GoogleOneTapStrategy,
9+
OAuthStrategy,
10+
PhoneCodeStrategy,
11+
TicketStrategy,
12+
Web3Strategy,
13+
} from './strategies';
614
import type { VerificationResource } from './verification';
715

816
export interface SignUpFutureAdditionalParams {
@@ -38,6 +46,17 @@ export interface SignUpFutureAdditionalParams {
3846
}
3947

4048
export interface SignUpFutureCreateParams extends SignUpFutureAdditionalParams {
49+
/**
50+
* The first factor verification strategy to use in the sign-in flow. Depends on the `identifier` value. Each
51+
* authentication identifier supports different verification strategies.
52+
*/
53+
strategy?:
54+
| OAuthStrategy
55+
| EnterpriseSSOStrategy
56+
| TicketStrategy
57+
| GoogleOneTapStrategy
58+
| AppleIdTokenStrategy
59+
| PhoneCodeStrategy;
4160
/**
4261
* The user's email address. Only supported if [Email address](https://clerk.com/docs/guides/configure/auth-strategies/sign-up-sign-in-options#email)
4362
* is enabled. Keep in mind that the email address requires an extra verification process.
@@ -55,6 +74,11 @@ export interface SignUpFutureCreateParams extends SignUpFutureAdditionalParams {
5574
* the instance settings.
5675
*/
5776
username?: string;
77+
/**
78+
* The user's password. Only supported if
79+
* [password](https://clerk.com/docs/guides/configure/auth-strategies/sign-up-sign-in-options#password) is enabled.
80+
*/
81+
password?: string;
5882
/**
5983
* When set to `true`, the `SignUp` will attempt to retrieve information from the active `SignIn` instance and use it
6084
* to complete the sign-up process. This is useful when you want to seamlessly transition a user from a sign-in

0 commit comments

Comments
 (0)