Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user management support API types #944

Draft
wants to merge 12 commits into
base: 21.0
Choose a base branch
from
Draft
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
73 changes: 72 additions & 1 deletion lib/build/recipe/accountlinking/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-nocheck
import type { BaseRequest, BaseResponse } from "../../framework";
import OverrideableBuilder from "supertokens-js-override";
import type { User, UserContext } from "../../types";
import type { GeneralErrorResponse, NormalisedAppinfo, User, UserContext } from "../../types";
import RecipeUserId from "../../recipeUserId";
import { SessionContainerInterface } from "../session/types";
export declare type TypeInput = {
Expand Down Expand Up @@ -175,6 +176,76 @@ export declare type RecipeInterface = {
status: "OK";
}>;
};
export declare type APIOptions = {
recipeImplementation: RecipeInterface;
appInfo: NormalisedAppinfo;
config: TypeNormalisedInput;
recipeId: string;
isInServerlessEnv: boolean;
req: BaseRequest;
res: BaseResponse;
};
export declare type APIInterface = {
userDetailsGET:
| undefined
| ((input: {
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
user: User;
}
| GeneralErrorResponse
>);
userEnabledDetailsGET:
| undefined
| ((input: {
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
enabledRecipes: string[];
shouldDoAutomaticAccountLinking: boolean;
}
| GeneralErrorResponse
>);
loginMethodDELETE:
| undefined
| ((input: {
recipeId: string;
recipeUserId: string;
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
}
| GeneralErrorResponse
>);
updateUserDetailsPOST:
| undefined
| ((input: {
firstName: string;
lastName: string;
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
}
| {
status: "USER_DETAILS_UPDATE_NOT_ALLOWED";
reason: string;
}
| GeneralErrorResponse
>);
};
export declare type AccountInfo = {
email?: string;
phoneNumber?: string;
Expand Down
2 changes: 2 additions & 0 deletions lib/build/recipe/emailpassword/api/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,8 @@ function getAPIImplementation() {
user: postAuthChecks.user,
};
},
updatePasswordPOST: undefined,
changeEmailPOST: undefined,
};
}
exports.default = getAPIImplementation;
43 changes: 43 additions & 0 deletions lib/build/recipe/emailpassword/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,49 @@ export declare type APIInterface = {
}
| GeneralErrorResponse
>);
updatePasswordPOST:
| undefined
| ((input: {
newPassword: string;
oldPassword: string;
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
}
| {
status: "WRONG_CREDENTIALS_ERROR";
}
| {
status: "PASSWORD_POLICY_VIOLATED_ERROR";
failureReason: string;
}
| GeneralErrorResponse
>);
changeEmailPOST:
| undefined
| ((input: {
email: string;
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
}
| {
status: "EMAIL_VERIFICATION_SENT";
}
| {
status: "EMAIL_ALREADY_EXISTS_ERROR";
}
| {
status: "EMAIL_CHANGE_NOT_ALLOWED_ERROR";
}
| GeneralErrorResponse
>);
};
export declare type TypeEmailPasswordPasswordResetEmailDeliveryInput = {
type: "PASSWORD_RESET";
Expand Down
3 changes: 3 additions & 0 deletions lib/build/recipe/multifactorauth/api/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ function getAPIInterface() {
phoneNumbers: getPhoneNumbersForFactorsResult.factorIdToPhoneNumberMap,
};
},
factorsForUserGET: undefined,
addFactorForUserPOST: undefined,
deleteFactorForUserDELETE: undefined,
};
}
exports.default = getAPIInterface;
39 changes: 39 additions & 0 deletions lib/build/recipe/multifactorauth/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,45 @@ export declare type APIInterface = {
}
| GeneralErrorResponse
>);
factorsForUserGET:
| undefined
| ((input: {
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
factors: string[];
}
| GeneralErrorResponse
>);
addFactorForUserPOST:
| undefined
| ((input: {
factorId: string;
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
}
| GeneralErrorResponse
>);
deleteFactorForUserDELETE:
| undefined
| ((input: {
factorId: string;
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
}
| GeneralErrorResponse
>);
};
export declare type GetFactorsSetupForUserFromOtherRecipesFunc = (
user: User,
Expand Down
2 changes: 2 additions & 0 deletions lib/build/recipe/session/api/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function getAPIInterface() {
status: "OK",
};
},
allSessionsGET: undefined,
revokeSessionPOST: undefined,
};
}
exports.default = getAPIInterface;
26 changes: 26 additions & 0 deletions lib/build/recipe/session/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,32 @@ export declare type APIInterface = {
}
| GeneralErrorResponse
>);
allSessionsGET:
| undefined
| ((input: {
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
sessions: SessionInformation[];
}
| GeneralErrorResponse
>);
revokeSessionPOST:
| undefined
| ((input: {
sessionHandle: string;
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
}
| GeneralErrorResponse
>);
verifySession(input: {
verifySessionOptions: VerifySessionOptions | undefined;
options: APIOptions;
Expand Down
75 changes: 74 additions & 1 deletion lib/ts/recipe/accountlinking/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
* under the License.
*/

import type { BaseRequest, BaseResponse } from "../../framework";
import OverrideableBuilder from "supertokens-js-override";
import type { User, UserContext } from "../../types";
import type { GeneralErrorResponse, NormalisedAppinfo, User, UserContext } from "../../types";
import RecipeUserId from "../../recipeUserId";
import { SessionContainerInterface } from "../session/types";

Expand Down Expand Up @@ -185,6 +186,78 @@ export type RecipeInterface = {
}) => Promise<{ status: "OK" }>;
};

export type APIOptions = {
recipeImplementation: RecipeInterface;
appInfo: NormalisedAppinfo;
config: TypeNormalisedInput;
recipeId: string;
isInServerlessEnv: boolean;
req: BaseRequest;
res: BaseResponse;
};

export type APIInterface = {
userDetailsGET:
| undefined
| ((input: {
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
user: User;
}
| GeneralErrorResponse
>);

userEnabledDetailsGET:
| undefined
| ((input: {
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
enabledRecipes: string[];
shouldDoAutomaticAccountLinking: boolean;
}
| GeneralErrorResponse
>);

loginMethodDELETE:
| undefined
| ((input: {
recipeId: string;
recipeUserId: string;
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
}
| GeneralErrorResponse
>);

updateUserDetailsPOST:
| undefined
| ((input: {
firstName: string;
lastName: string;
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
}
| { status: "USER_DETAILS_UPDATE_NOT_ALLOWED"; reason: string }
| GeneralErrorResponse
>);
};

export type AccountInfo = {
email?: string;
phoneNumber?: string;
Expand Down
3 changes: 3 additions & 0 deletions lib/ts/recipe/emailpassword/api/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,5 +926,8 @@ export default function getAPIImplementation(): APIInterface {
user: postAuthChecks.user,
};
},

updatePasswordPOST: undefined,
changeEmailPOST: undefined,
};
}
34 changes: 34 additions & 0 deletions lib/ts/recipe/emailpassword/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,40 @@ export type APIInterface = {
}
| GeneralErrorResponse
>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try out (emailverification in required mode, and account linking switched on):

  • First factor is passwordless -> login with email A, then call the signUpPOST API with email A and some password and the access token of the session. See what happens.
  • First factor is passwordless -> login with email A, mark email A as unverified, then call the signUpPOST API with email A and some password and the access token of the session. See what happens.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API can be called when setting a password for an existing account that has no email password login method.


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a new email will entail adding a passwordless flow

updatePasswordPOST:
| undefined
| ((input: {
newPassword: string;
oldPassword: string;
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
}
| { status: "WRONG_CREDENTIALS_ERROR" }
| { status: "PASSWORD_POLICY_VIOLATED_ERROR"; failureReason: string }
| GeneralErrorResponse
>);

deepjyoti30-st marked this conversation as resolved.
Show resolved Hide resolved
changeEmailPOST:
| undefined
| ((input: {
email: string;
session: SessionContainerInterface;
options: APIOptions;
userContext: UserContext;
}) => Promise<
| {
status: "OK";
}
| { status: "EMAIL_VERIFICATION_SENT" }
| { status: "EMAIL_ALREADY_EXISTS_ERROR" }
| { status: "EMAIL_CHANGE_NOT_ALLOWED_ERROR" }
| GeneralErrorResponse
>);
};

deepjyoti30-st marked this conversation as resolved.
Show resolved Hide resolved
deepjyoti30-st marked this conversation as resolved.
Show resolved Hide resolved
export type TypeEmailPasswordPasswordResetEmailDeliveryInput = {
deepjyoti30-st marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
3 changes: 3 additions & 0 deletions lib/ts/recipe/multifactorauth/api/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,8 @@ export default function getAPIInterface(): APIInterface {
phoneNumbers: getPhoneNumbersForFactorsResult.factorIdToPhoneNumberMap,
};
},
factorsForUserGET: undefined,
addFactorForUserPOST: undefined,
deleteFactorForUserDELETE: undefined,
};
}
Loading
Loading