import type * as cip from "@distilled.cloud/aws/cognito-identity-provider"; import type * as Effect from "effect/Effect"; import * as Binding from "../../Binding.ts"; import type { UserPoolClient } from "./UserPoolClient.ts"; export interface SignUpRequest extends Omit { } export interface ConfirmSignUpRequest extends Omit { } export interface ResendConfirmationCodeRequest extends Omit { } export interface InitiateAuthRequest extends Omit { } export interface RespondToAuthChallengeRequest extends Omit { } export interface ForgotPasswordRequest extends Omit { } export interface ConfirmForgotPasswordRequest extends Omit { } export interface RevokeTokenRequest extends Omit { } export interface GetTokensFromRefreshTokenRequest extends Omit { } /** * The typed client returned by binding {@link UserPoolAuth} to a * `UserPoolClient`. Every method automatically injects the app client ID. */ export interface UserPoolAuthClient { /** Register a new user (public sign-up flow). */ signUp: (request: SignUpRequest) => Effect.Effect; /** Confirm a sign-up with the emailed/SMSed confirmation code. */ confirmSignUp: (request: ConfirmSignUpRequest) => Effect.Effect; /** Resend the sign-up confirmation code. */ resendConfirmationCode: (request: ResendConfirmationCodeRequest) => Effect.Effect; /** Start an authentication flow (e.g. `USER_PASSWORD_AUTH`). */ initiateAuth: (request: InitiateAuthRequest) => Effect.Effect; /** Answer an auth challenge returned by `initiateAuth`. */ respondToAuthChallenge: (request: RespondToAuthChallengeRequest) => Effect.Effect; /** Start the forgot-password flow. */ forgotPassword: (request: ForgotPasswordRequest) => Effect.Effect; /** Complete the forgot-password flow with the confirmation code. */ confirmForgotPassword: (request: ConfirmForgotPasswordRequest) => Effect.Effect; /** Fetch the signed-in user's profile from an access token. */ getUser: (request: cip.GetUserRequest) => Effect.Effect; /** Sign the user out of all devices (invalidates tokens). */ globalSignOut: (request: cip.GlobalSignOutRequest) => Effect.Effect; /** Revoke a refresh token and all access tokens derived from it. */ revokeToken: (request: RevokeTokenRequest) => Effect.Effect; /** Exchange a refresh token for fresh access/ID tokens (refresh-token * rotation aware). */ getTokensFromRefreshToken: (request: GetTokensFromRefreshTokenRequest) => Effect.Effect; /** Change the signed-in user's password. */ changePassword: (request: cip.ChangePasswordRequest) => Effect.Effect; /** Update the signed-in user's attributes. */ updateUserAttributes: (request: cip.UpdateUserAttributesRequest) => Effect.Effect; /** Delete attributes from the signed-in user's profile. */ deleteUserAttributes: (request: cip.DeleteUserAttributesRequest) => Effect.Effect; /** Send a verification code for an updated attribute (email/phone). */ getUserAttributeVerificationCode: (request: cip.GetUserAttributeVerificationCodeRequest) => Effect.Effect; /** Verify an attribute with the code delivered to it. */ verifyUserAttribute: (request: cip.VerifyUserAttributeRequest) => Effect.Effect; /** Set the signed-in user's MFA preferences (SMS / TOTP / email). */ setUserMFAPreference: (request: cip.SetUserMFAPreferenceRequest) => Effect.Effect; /** Begin TOTP enrollment: returns the shared secret to seed the * authenticator app. */ associateSoftwareToken: (request: cip.AssociateSoftwareTokenRequest) => Effect.Effect; /** Complete TOTP enrollment by verifying a generated code. */ verifySoftwareToken: (request: cip.VerifySoftwareTokenRequest) => Effect.Effect; /** List the auth factors configured for the signed-in user. */ getUserAuthFactors: (request: cip.GetUserAuthFactorsRequest) => Effect.Effect; /** Delete the signed-in user's own account. */ deleteUser: (request: cip.DeleteUserRequest) => Effect.Effect; } /** * Runtime binding for the public (client-side) Cognito user pool auth flows. * * Bind this to a `UserPoolClient` inside a function runtime to get a typed * client for sign-up, sign-in, and token flows. These operations are * unauthenticated (Cognito does not evaluate IAM for them), so the binding * grants no IAM policy — it injects the app client ID into every call. * ### Authenticating Users * **Example:** Username/Password Sign-In * ```typescript * const auth = yield* Cognito.UserPoolAuth(client); * * const result = yield* auth.initiateAuth({ * AuthFlow: "USER_PASSWORD_AUTH", * AuthParameters: { USERNAME: username, PASSWORD: password }, * }); * const idToken = result.AuthenticationResult?.IdToken; * ``` * * **Example:** Sign-Up and Confirmation * ```typescript * yield* auth.signUp({ * Username: "user@example.com", * Password: "Sup3r-secret!", * UserAttributes: [{ Name: "email", Value: "user@example.com" }], * }); * yield* auth.confirmSignUp({ * Username: "user@example.com", * ConfirmationCode: code, * }); * ``` * * **Example:** Read the Signed-In User * ```typescript * const user = yield* auth.getUser({ AccessToken: accessToken }); * ``` * * ### Self-Service Account Management * **Example:** Change Password and Update Attributes * ```typescript * yield* auth.changePassword({ * AccessToken: accessToken, * PreviousPassword: oldPassword, * ProposedPassword: newPassword, * }); * yield* auth.updateUserAttributes({ * AccessToken: accessToken, * UserAttributes: [{ Name: "nickname", Value: "sam" }], * }); * ``` * * **Example:** Refresh Tokens * ```typescript * const refreshed = yield* auth.getTokensFromRefreshToken({ * RefreshToken: refreshToken, * }); * ``` * * @binding */ export interface UserPoolAuth extends Binding.Service(client: C) => Effect.Effect> { } export declare const UserPoolAuth: UserPoolAuth; //# sourceMappingURL=UserPoolAuth.d.ts.map