@gahojin-inc/amplify-auth-hooks 2026.2.0 → 2026.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authenticator.d.ts +7 -0
- package/dist/authenticator.js +2 -0
- package/dist/{defaultAuthHubHandler-BeifIloE.js → defaultAuthHubHandler-rX4tAlCj.js} +2 -3
- package/dist/{defaultAuthHubHandler-BeifIloE.js.map → defaultAuthHubHandler-rX4tAlCj.js.map} +1 -1
- package/dist/index.d.ts +66 -0
- package/dist/{index.mjs → index.js} +4 -12
- package/dist/index.js.map +1 -0
- package/dist/{actor-DQxLXZVG.js → machines-BRfb3dTb.js} +220 -12
- package/dist/machines-BRfb3dTb.js.map +1 -0
- package/dist/machines.d.ts +2 -0
- package/dist/machines.js +2 -0
- package/dist/types-BQSOxe-R.d.ts +116 -0
- package/package.json +13 -12
- package/dist/actor-DQxLXZVG.js.map +0 -1
- package/dist/authenticator/defaultAuthHubHandler.d.mts +0 -3
- package/dist/authenticator/types.d.mts +0 -11
- package/dist/authenticator.d.mts +0 -1
- package/dist/authenticator.mjs +0 -3
- package/dist/context/AuthenticatorContext.d.mts +0 -7
- package/dist/context/AuthenticatorProvider.d.mts +0 -7
- package/dist/context/index.d.mts +0 -2
- package/dist/hooks/facade.d.mts +0 -6
- package/dist/hooks/types.d.mts +0 -29
- package/dist/hooks/useAuth.d.mts +0 -12
- package/dist/hooks/useAuthenticator.d.mts +0 -2
- package/dist/hooks/utils.d.mts +0 -87
- package/dist/index.d.mts +0 -6
- package/dist/index.mjs.map +0 -1
- package/dist/machines/actions.d.mts +0 -25
- package/dist/machines/defaultHandlers.d.mts +0 -2
- package/dist/machines/forgotPassword/actor.d.mts +0 -1
- package/dist/machines/guards.d.mts +0 -22
- package/dist/machines/signIn/actor.d.mts +0 -1
- package/dist/machines/signOut/actor.d.mts +0 -1
- package/dist/machines/signUp/actor.d.mts +0 -1
- package/dist/machines/types.d.mts +0 -96
- package/dist/machines/verifyUserAttributes/actor.d.mts +0 -1
- package/dist/machines.d.mts +0 -5
- package/dist/machines.mjs +0 -222
- package/dist/machines.mjs.map +0 -1
- package/dist/utils.d.mts +0 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { n as AuthMachineHubHandler, r as StopListenerCallback, t as AuthActor } from "./types-BQSOxe-R.js";
|
|
2
|
+
|
|
3
|
+
//#region src/authenticator/defaultAuthHubHandler.d.ts
|
|
4
|
+
declare const listenToAuthHub: (actor: AuthActor, handler?: AuthMachineHubHandler) => StopListenerCallback;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { listenToAuthHub };
|
|
7
|
+
//# sourceMappingURL=authenticator.d.ts.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Hub } from "@aws-amplify/core";
|
|
2
2
|
import { AmplifyErrorCode } from "@aws-amplify/core/internals/utils";
|
|
3
|
-
|
|
4
3
|
//#region src/authenticator/defaultAuthHubHandler.ts
|
|
5
4
|
const defaultAuthHubHandler = ({ payload }, actor, options) => {
|
|
6
5
|
const { data, event } = payload;
|
|
@@ -28,7 +27,7 @@ const listenToAuthHub = (actor, handler = defaultAuthHubHandler) => {
|
|
|
28
27
|
const eventHandler = (data) => handler(data, actor);
|
|
29
28
|
return Hub.listen("auth", eventHandler, "authenticator-hub-handler");
|
|
30
29
|
};
|
|
31
|
-
|
|
32
30
|
//#endregion
|
|
33
31
|
export { listenToAuthHub as n, defaultAuthHubHandler as t };
|
|
34
|
-
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=defaultAuthHubHandler-rX4tAlCj.js.map
|
package/dist/{defaultAuthHubHandler-BeifIloE.js.map → defaultAuthHubHandler-rX4tAlCj.js.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaultAuthHubHandler-
|
|
1
|
+
{"version":3,"file":"defaultAuthHubHandler-rX4tAlCj.js","names":[],"sources":["../src/authenticator/defaultAuthHubHandler.ts"],"sourcesContent":["/*\n * Copyright 2017 - 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * (C) 2025 GAHOJIN, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n */\n\nimport { Hub } from '@aws-amplify/core'\nimport { AmplifyErrorCode } from '@aws-amplify/core/internals/utils'\nimport type { AuthActor, AuthMachineHubHandler, StopListenerCallback } from './types'\n\nexport const defaultAuthHubHandler: AuthMachineHubHandler = ({ payload }, actor, options) => {\n const { data, event } = payload\n const { send } = actor\n const { onSignIn, onSignOut } = options ?? {}\n\n switch (event) {\n case 'signedIn': {\n if (typeof onSignIn === 'function') {\n onSignIn(payload)\n }\n break\n }\n case 'signInWithRedirect': {\n send({ type: 'SIGN_IN_WITH_REDIRECT' })\n break\n }\n case 'signedOut': {\n if (typeof onSignOut === 'function') {\n onSignOut()\n }\n send({ type: 'SIGN_OUT' })\n break\n }\n case 'tokenRefresh_failure': {\n if (data?.error?.name === AmplifyErrorCode.NetworkError) {\n return\n }\n send({ type: 'SIGN_OUT' })\n break\n }\n default: {\n break\n }\n }\n}\n\nexport const listenToAuthHub = (actor: AuthActor, handler: AuthMachineHubHandler = defaultAuthHubHandler): StopListenerCallback => {\n const eventHandler: Parameters<typeof Hub.listen>[1] = (data) => handler(data, actor)\n return Hub.listen('auth', eventHandler, 'authenticator-hub-handler')\n}\n"],"mappings":";;;AAeA,MAAa,yBAAgD,EAAE,WAAW,OAAO,YAAY;CAC3F,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,EAAE,SAAS;CACjB,MAAM,EAAE,UAAU,cAAc,WAAW,EAAE;AAE7C,SAAQ,OAAR;EACE,KAAK;AACH,OAAI,OAAO,aAAa,WACtB,UAAS,QAAQ;AAEnB;EAEF,KAAK;AACH,QAAK,EAAE,MAAM,yBAAyB,CAAC;AACvC;EAEF,KAAK;AACH,OAAI,OAAO,cAAc,WACvB,YAAW;AAEb,QAAK,EAAE,MAAM,YAAY,CAAC;AAC1B;EAEF,KAAK;AACH,OAAI,MAAM,OAAO,SAAS,iBAAiB,aACzC;AAEF,QAAK,EAAE,MAAM,YAAY,CAAC;AAC1B;EAEF,QACE;;;AAKN,MAAa,mBAAmB,OAAkB,UAAiC,0BAAgD;CACjI,MAAM,gBAAkD,SAAS,QAAQ,MAAM,MAAM;AACrF,QAAO,IAAI,OAAO,QAAQ,cAAc,4BAA4B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { A as UserAttributeStep, C as SignInStep, D as Step, E as SignUpStep, M as unverifiedContactMethodTypes, O as UnverifiedContactMethodType, S as SignInContext, T as SignUpContext, _ as InitialRoute, a as ActorDoneData, b as ResetPasswordContext, c as AuthContext, d as AuthEventData, f as AuthEventTypes, g as Handlers, h as FederatedIdentityProviders, i as AuthenticatorMachineOptions, j as VerifyUserContext, k as UnverifiedUserAttributes, l as AuthError, m as AuthTOTPSetupDetails, o as AuthActorContext, p as AuthMFAType, s as AuthAllowedMFATypes, t as AuthActor, u as AuthEvent, v as InitialStep, w as SignOutContext, x as ResetPasswordStep, y as NavigableRoute } from "./types-BQSOxe-R.js";
|
|
2
|
+
import { Context, JSX, PropsWithChildren } from "react";
|
|
3
|
+
import { AuthUser, CodeDeliveryDetails } from "@aws-amplify/auth";
|
|
4
|
+
|
|
5
|
+
//#region src/context/AuthenticatorContext.d.ts
|
|
6
|
+
type AuthenticatorContextType = {
|
|
7
|
+
actor: AuthActor;
|
|
8
|
+
};
|
|
9
|
+
declare const AuthenticatorContext: Context<AuthenticatorContextType | null>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/context/AuthenticatorProvider.d.ts
|
|
12
|
+
type Props$1 = PropsWithChildren & {
|
|
13
|
+
options?: AuthenticatorMachineOptions;
|
|
14
|
+
};
|
|
15
|
+
declare const _default: ({
|
|
16
|
+
options,
|
|
17
|
+
children
|
|
18
|
+
}: Props$1) => JSX.Element;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/hooks/types.d.ts
|
|
21
|
+
type AuthenticatorRoute = "authenticated" | "confirmResetPassword" | "confirmSignIn" | "confirmSignUp" | "confirmVerifyUser" | "forceNewPassword" | "idle" | "forgotPassword" | "setup" | "signOut" | "selectMfaType" | "setupEmail" | "setupTotp" | "signIn" | "signUp" | "transition" | "verifyUser";
|
|
22
|
+
type AuthenticatorMachineContext = AuthenticatorServiceFacade;
|
|
23
|
+
type AuthenticatorMachineContextKey = keyof AuthenticatorMachineContext;
|
|
24
|
+
type UseAuthenticatorSelector = (context: AuthenticatorServiceFacade) => AuthenticatorMachineContext[AuthenticatorMachineContextKey][];
|
|
25
|
+
type UseAuthenticator = AuthenticatorServiceFacade;
|
|
26
|
+
type AuthenticatorServiceContextFacade = {
|
|
27
|
+
allowedMfaTypes: AuthAllowedMFATypes | undefined;
|
|
28
|
+
codeDeliveryDetails: CodeDeliveryDetails | undefined;
|
|
29
|
+
errorMessage: string | undefined;
|
|
30
|
+
isPending: boolean;
|
|
31
|
+
route: AuthenticatorRoute | null;
|
|
32
|
+
totpSecretCode: string | undefined;
|
|
33
|
+
username: string | undefined;
|
|
34
|
+
user: AuthUser | undefined;
|
|
35
|
+
unverifiedUserAttributes: UnverifiedUserAttributes | undefined;
|
|
36
|
+
};
|
|
37
|
+
type AuthenticatorSendEventAliases = {
|
|
38
|
+
handleSubmit: (data?: AuthEventData) => void;
|
|
39
|
+
resendConfirmationCode: () => void;
|
|
40
|
+
refreshUser: () => void;
|
|
41
|
+
setRoute: (route: NavigableRoute) => void;
|
|
42
|
+
skipAttributeVerification: () => void;
|
|
43
|
+
toFederatedSignIn: (data?: AuthEventData) => void;
|
|
44
|
+
};
|
|
45
|
+
type AuthenticatorServiceFacade = AuthenticatorSendEventAliases & AuthenticatorServiceContextFacade;
|
|
46
|
+
type Comparator = (currentMachineContext: AuthenticatorMachineContext, nextMachineContext: AuthenticatorMachineContext) => boolean;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/hooks/useAuth.d.ts
|
|
49
|
+
type UseAuthResult = {
|
|
50
|
+
user?: AuthUser;
|
|
51
|
+
isLoading: boolean;
|
|
52
|
+
error?: Error;
|
|
53
|
+
};
|
|
54
|
+
type Props = {
|
|
55
|
+
getCurrentUser?: Handlers["getCurrentUser"];
|
|
56
|
+
};
|
|
57
|
+
declare const useAuth: (handlers?: Props) => UseAuthResult;
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/hooks/useAuthenticator.d.ts
|
|
60
|
+
declare const useAuthenticator: (selector?: UseAuthenticatorSelector) => UseAuthenticator;
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/utils.d.ts
|
|
63
|
+
declare const getTotpCodeURL: (issuer: string, username: string, secret: string) => string;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { ActorDoneData, AuthActorContext, AuthAllowedMFATypes, AuthContext, AuthError, AuthEvent, AuthEventData, AuthEventTypes, AuthMFAType, AuthTOTPSetupDetails, AuthenticatorContext, _default as AuthenticatorProvider, AuthenticatorRoute, AuthenticatorSendEventAliases, AuthenticatorServiceContextFacade, AuthenticatorServiceFacade, Comparator, FederatedIdentityProviders, Handlers, InitialRoute, InitialStep, NavigableRoute, ResetPasswordContext, ResetPasswordStep, SignInContext, SignInStep, SignOutContext, SignUpContext, SignUpStep, Step, UnverifiedContactMethodType, UnverifiedUserAttributes, type UseAuthResult, UseAuthenticator, UseAuthenticatorSelector, UserAttributeStep, VerifyUserContext, getTotpCodeURL, unverifiedContactMethodTypes, useAuth, useAuthenticator };
|
|
66
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { n as listenToAuthHub, t as defaultAuthHubHandler } from "./defaultAuthHubHandler-
|
|
2
|
-
import { createAuthenticatorMachine } from "./machines.
|
|
1
|
+
import { n as listenToAuthHub, t as defaultAuthHubHandler } from "./defaultAuthHubHandler-rX4tAlCj.js";
|
|
2
|
+
import { t as createAuthenticatorMachine } from "./machines-BRfb3dTb.js";
|
|
3
3
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
4
4
|
import { useActor, useSelector } from "@xstate/react";
|
|
5
5
|
import { Hub } from "@aws-amplify/core";
|
|
6
6
|
import { getCurrentUser } from "@aws-amplify/auth";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
|
|
9
8
|
//#region src/context/AuthenticatorContext.ts
|
|
10
9
|
const AuthenticatorContext = createContext(null);
|
|
11
|
-
|
|
12
10
|
//#endregion
|
|
13
11
|
//#region src/context/AuthenticatorProvider.tsx
|
|
14
12
|
const createHubHandler = (options) => {
|
|
@@ -28,7 +26,6 @@ var AuthenticatorProvider_default = ({ options, children }) => {
|
|
|
28
26
|
children
|
|
29
27
|
});
|
|
30
28
|
};
|
|
31
|
-
|
|
32
29
|
//#endregion
|
|
33
30
|
//#region src/hooks/useAuth.ts
|
|
34
31
|
const useAuth = (handlers) => {
|
|
@@ -85,7 +82,6 @@ const useAuth = (handlers) => {
|
|
|
85
82
|
}, [handleAuth, fetchCurrentUser]);
|
|
86
83
|
return result;
|
|
87
84
|
};
|
|
88
|
-
|
|
89
85
|
//#endregion
|
|
90
86
|
//#region src/hooks/facade.ts
|
|
91
87
|
const NAVIGABLE_ROUTE_EVENT = {
|
|
@@ -165,7 +161,6 @@ const getServiceContextFacade = (actor) => {
|
|
|
165
161
|
username
|
|
166
162
|
};
|
|
167
163
|
};
|
|
168
|
-
|
|
169
164
|
//#endregion
|
|
170
165
|
//#region src/hooks/utils.ts
|
|
171
166
|
/**
|
|
@@ -282,7 +277,6 @@ const getComparator = (selector) => {
|
|
|
282
277
|
return areSelectorDepsEqual(selector(currentFacade), selector(nextFacade));
|
|
283
278
|
};
|
|
284
279
|
};
|
|
285
|
-
|
|
286
280
|
//#endregion
|
|
287
281
|
//#region src/hooks/useAuthenticator.ts
|
|
288
282
|
const defaultComparator = () => false;
|
|
@@ -296,7 +290,6 @@ const useAuthenticator = (selector) => {
|
|
|
296
290
|
...getServiceContextFacade(snapshot)
|
|
297
291
|
}), selector ? getComparator(selector) : defaultComparator);
|
|
298
292
|
};
|
|
299
|
-
|
|
300
293
|
//#endregion
|
|
301
294
|
//#region src/machines/types.ts
|
|
302
295
|
const FederatedIdentityProviders = {
|
|
@@ -309,13 +302,12 @@ const FederatedIdentityProviders = {
|
|
|
309
302
|
* Cognito user contact method types that have not been verified as valid
|
|
310
303
|
*/
|
|
311
304
|
const unverifiedContactMethodTypes = ["email", "phone_number"];
|
|
312
|
-
|
|
313
305
|
//#endregion
|
|
314
306
|
//#region src/utils.ts
|
|
315
307
|
const getTotpCodeURL = (issuer, username, secret) => {
|
|
316
308
|
return encodeURI(`otpauth://totp/${issuer}:${username}?secret=${secret}&issuer=${issuer}`);
|
|
317
309
|
};
|
|
318
|
-
|
|
319
310
|
//#endregion
|
|
320
311
|
export { AuthenticatorContext, AuthenticatorProvider_default as AuthenticatorProvider, FederatedIdentityProviders, getTotpCodeURL, unverifiedContactMethodTypes, useAuth, useAuthenticator };
|
|
321
|
-
|
|
312
|
+
|
|
313
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/context/AuthenticatorContext.ts","../src/context/AuthenticatorProvider.tsx","../src/hooks/useAuth.ts","../src/hooks/facade.ts","../src/hooks/utils.ts","../src/hooks/useAuthenticator.ts","../src/machines/types.ts","../src/utils.ts"],"sourcesContent":["import { type Context, createContext } from 'react'\nimport type { AuthActor } from '../authenticator/types'\n\ntype AuthenticatorContextType = {\n actor: AuthActor\n}\n\nexport const AuthenticatorContext: Context<AuthenticatorContextType | null> = createContext<AuthenticatorContextType | null>(null)\n","import { useActor } from '@xstate/react'\nimport { type JSX, type PropsWithChildren, useContext, useEffect, useMemo } from 'react'\nimport { defaultAuthHubHandler, listenToAuthHub } from '../authenticator/defaultAuthHubHandler'\nimport type { AuthMachineHubHandler, AuthMachineHubHandlerOptions } from '../authenticator/types'\nimport { AuthenticatorContext } from '../context/AuthenticatorContext'\nimport { type AuthenticatorMachineOptions, createAuthenticatorMachine } from '../machines'\n\nconst createHubHandler = (options?: AuthMachineHubHandlerOptions): AuthMachineHubHandler => {\n return (data, service) => defaultAuthHubHandler(data, service, options)\n}\n\ntype Props = PropsWithChildren & {\n options?: AuthenticatorMachineOptions\n}\n\nexport default ({ options, children }: Props): JSX.Element => {\n const machine = useMemo(() => createAuthenticatorMachine(options), [options])\n\n // 階層構造にAuthenticatorContextを使用している場合、親Contextの認証状態を継承する\n const parentProvider = useContext(AuthenticatorContext)\n const [, , actor] = useActor(machine)\n const value = useMemo(() => parentProvider ?? { actor }, [parentProvider, actor])\n\n const { actor: activeActor } = value\n\n useEffect(() => {\n return listenToAuthHub(activeActor, createHubHandler(options))\n }, [activeActor, options])\n\n return <AuthenticatorContext.Provider value={value}>{children}</AuthenticatorContext.Provider>\n}\n","/*\n * Copyright 2017 - 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * (C) 2025 GAHOJIN, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n */\n\nimport { type AuthUser, getCurrentUser } from '@aws-amplify/auth'\nimport { Hub, type HubCallback } from '@aws-amplify/core'\nimport { useCallback, useEffect, useState } from 'react'\nimport type { Handlers } from '../machines/types'\n\nexport type UseAuthResult = {\n user?: AuthUser\n isLoading: boolean\n error?: Error\n}\n\ntype Props = {\n getCurrentUser?: Handlers['getCurrentUser']\n}\n\nexport const useAuth = (handlers?: Props): UseAuthResult => {\n const [result, setResult] = useState<UseAuthResult>({\n isLoading: true,\n })\n\n const fetchCurrentUser = useCallback(() => {\n // loading\n setResult((prev) => ({ ...prev, isLoading: true }))\n\n void (handlers?.getCurrentUser ?? getCurrentUser)()\n .then((user) => setResult({ user, isLoading: false }))\n .catch((e) => setResult({ error: e as Error, isLoading: false }))\n }, [handlers?.getCurrentUser])\n\n const handleAuth: HubCallback = useCallback(\n ({ payload }) => {\n switch (payload.event) {\n // success events\n case 'signedIn':\n case 'signUp':\n case 'autoSignIn':\n setResult({ user: payload.data as AuthUser, isLoading: false })\n break\n case 'signedOut':\n setResult({ isLoading: false })\n break\n\n // failure events\n case 'tokenRefresh_failure':\n case 'signIn_failure':\n setResult({ error: payload.data as Error, isLoading: false })\n break\n case 'autoSignIn_failure':\n // autoSignIn just returns error message. Wrap it to an Error object\n setResult({ error: new Error(payload.message), isLoading: false })\n break\n\n // events that need another fetch\n case 'tokenRefresh':\n void fetchCurrentUser()\n break\n\n default:\n // we do not handle other hub events like `configured`.\n break\n }\n },\n [fetchCurrentUser],\n )\n\n useEffect(() => {\n const unsubscribe = Hub.listen('auth', handleAuth, 'useAuth')\n void fetchCurrentUser() // on init, see if user is already logged in\n\n return unsubscribe\n }, [handleAuth, fetchCurrentUser])\n\n return result\n}\n","import type { AnyMachineSnapshot, SnapshotFrom } from 'xstate'\nimport type { AuthActor } from '../authenticator/types'\nimport type { AuthActorContext, AuthEvent, AuthEventTypes, NavigableRoute } from '../machines/types'\nimport type { AuthenticatorRoute, AuthenticatorSendEventAliases, AuthenticatorServiceContextFacade } from './types'\n\nconst NAVIGABLE_ROUTE_EVENT: Record<NavigableRoute, AuthEventTypes> = {\n forgotPassword: 'FORGOT_PASSWORD',\n signIn: 'SIGN_IN',\n signUp: 'SIGN_UP',\n signOut: 'SIGN_OUT',\n}\n\nexport const getSendEventAliases = (send: (event: AuthEvent) => void): AuthenticatorSendEventAliases => {\n return {\n handleSubmit: (data) => send({ type: 'SUBMIT', data }),\n resendConfirmationCode: () => send({ type: 'RESEND' }),\n refreshUser: () => send({ type: 'TOKEN_REFRESH' }),\n setRoute: (route) => send({ type: NAVIGABLE_ROUTE_EVENT[route] }),\n skipAttributeVerification: () => send({ type: 'SKIP' }),\n toFederatedSignIn: () => send({ type: 'FEDERATED_SIGN_IN' }),\n }\n}\n\nconst getChildActor = (snapshot: SnapshotFrom<AuthActor>): AnyMachineSnapshot | undefined => {\n return snapshot.children?.childActor?.getSnapshot() as AnyMachineSnapshot\n}\n\nconst getRoute = (actor: SnapshotFrom<AuthActor>, childActor: AnyMachineSnapshot | undefined): AuthenticatorRoute | null => {\n // 'federatedSignIn' exists as a state on both the 'signInActor' and 'signUpActor',\n // match against the `actorState` initially to determine if the federated sign in flow\n // has begun, then which actor has begun the flow and return the corresponding `route`\n if (childActor?.matches('federatedSignIn')) {\n if (actor.matches('signUpActor')) {\n return 'signUp'\n }\n if (actor.matches('signInActor')) {\n return 'signIn'\n }\n }\n\n switch (true) {\n case actor.matches('idle'):\n return 'idle'\n case actor.matches('setup'):\n return 'setup'\n case actor.matches('signOut'):\n return 'signOut'\n case actor.matches('authenticated'):\n return 'authenticated'\n case childActor?.matches('confirmSignUp'):\n case childActor?.matches('resendSignUpCode'):\n return 'confirmSignUp'\n case childActor?.matches('confirmSignIn'):\n return 'confirmSignIn'\n case childActor?.matches('setupTotp'):\n return 'setupTotp'\n case childActor?.matches('signIn'):\n return 'signIn'\n case childActor?.matches('signUp'):\n case childActor?.matches('autoSignIn'):\n return 'signUp'\n case childActor?.matches('forceChangePassword'):\n return 'forceNewPassword'\n case childActor?.matches('forgotPassword'):\n return 'forgotPassword'\n case childActor?.matches('confirmResetPassword'):\n return 'confirmResetPassword'\n case childActor?.matches('selectUserAttributes'):\n return 'verifyUser'\n case childActor?.matches('confirmVerifyUserAttribute'):\n return 'confirmVerifyUser'\n case childActor?.matches('setupEmail'):\n return 'setupEmail'\n case childActor?.matches('selectMfaType'):\n return 'selectMfaType'\n case actor.matches('getCurrentUser'):\n case childActor?.matches('fetchUserAttributes'):\n /**\n * This route is needed for autoSignIn to capture both the\n * autoSignIn.pending and the resolved states when the\n * signIn actor is running.\n */\n return 'transition'\n default:\n return null\n }\n}\n\nexport const getServiceContextFacade = (actor: SnapshotFrom<AuthActor>): AuthenticatorServiceContextFacade => {\n const childActor = getChildActor(actor)\n const isPending = (actor.hasTag('pending') || childActor?.hasTag('pending')) ?? false\n const route = getRoute(actor, childActor)\n const context = actor.context\n const actorContext: AuthActorContext = childActor?.context ?? {}\n const user = actorContext?.user ?? context.user\n\n const { allowedMfaTypes, codeDeliveryDetails, remoteError: errorMessage, totpSecretCode, unverifiedUserAttributes, username } = actorContext\n\n return {\n allowedMfaTypes,\n codeDeliveryDetails,\n errorMessage,\n isPending,\n route,\n totpSecretCode,\n unverifiedUserAttributes,\n user,\n username,\n }\n}\n","/*\n * Copyright 2017 - 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * (C) 2025 GAHOJIN, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n */\n\nimport type { Comparator, UseAuthenticatorSelector } from '../hooks/types'\n\n/**\n * Checks if `value` is an Object (non-primitive, non-array, non-function)\n * Will return false for Arrays and functions\n *\n *\n * @param {unknown} value The value to check\n * @returns {boolean} Returns `true` if `value` is an object, `false` otherwise\n */\nexport function isObject(value: unknown): value is object {\n return value != null && !Array.isArray(value) && typeof value === 'object'\n}\n\n/**\n * Checks if `value` is a string primitive or object\n *\n * @param {unknown} value The value to check\n * @returns {boolean} Returns `true` if `value` is a string, `false` otherwise\n */\nexport function isString(value: unknown): value is string {\n return typeof value === 'string' || (typeof value === 'object' && Object.prototype.toString.call(value) === '[object String]')\n}\n\n/**\n * Checks if `value` is a Map\n *\n * @param {unknown} value The value to check\n * @returns {boolean} Returns `true` if `value` is a Map, `false` otherwise\n */\nexport function isMap(value: unknown): value is Map<unknown, unknown> {\n return isObject(value) && Object.prototype.toString.call(value) === '[object Map]'\n}\n\n/**\n * Checks if `value` is a Set\n *\n * @param {unknown} value The value to check\n * @returns {boolean} Returns `true` if `value` is a Set, `false` otherwise\n */\nexport function isSet<T>(value: unknown): value is Set<T> {\n return isObject(value) && Object.prototype.toString.call(value) === '[object Set]'\n}\n\n/**\n * Checks if `value` is undefined\n *\n * @param {unknown} value The value to check\n * @returns {boolean} Returns `true` if `value` is undefined, `false` otherwise\n */\nexport function isUndefined(value: unknown): value is undefined {\n return value === undefined\n}\n\n/**\n * Checks if `value` is nullish\n *\n * @param {unknown} value The value to check\n * @returns {boolean} Returns `true` if `value` is nullish, `false` otherwise\n */\nexport function isNil(value: unknown): value is null | undefined {\n return value == null\n}\n\n/**\n * Checks if `value` is empty\n *\n * @param {unknown} value The value to check\n * @returns {boolean} Returns `true` if `value` is empty, `false` otherwise\n */\nexport function isEmpty<T>(value: T): boolean {\n if (value === null || value === undefined) return true\n\n if (isObject(value) && (isMap(value) || isSet(value))) {\n return !value.size\n }\n if (isObject(value) && (isString(value) || Array.isArray(value))) {\n return !value.length\n }\n for (const key in value) {\n if (has(value, key)) {\n return false\n }\n }\n return true\n}\n\n/**\n * Checks if `value` is an empty array\n *\n * @param {unknown} value The value to check\n * @returns {boolean} Returns `true` if `value` is a empty, `false` otherwise\n */\nfunction isEmptyArray<T>(value: T): boolean {\n return Array.isArray(value) && isEmpty(value)\n}\n\n/**\n * Checks if all members of the `values` param are empty arrays\n *\n * @param {unknown} value The values to check\n * @returns {boolean} Returns `true` if all members of `values` are empty, `false` otherwise\n */\nexport function areEmptyArrays<T>(...values: T[]): boolean {\n return values.every(isEmptyArray)\n}\n\n/**\n * Checks if `value` is an empty object\n *\n * @param {unknown} value The value to check\n * @returns {boolean} Returns `true` if `value` is empty, `false` otherwise\n */\nexport function isEmptyObject<T>(value: T): boolean {\n return isObject(value) && isEmpty(value)\n}\n\n/**\n * Checks if all members of the `values` param are empty objects\n *\n * @param {unknown} values The values to check\n * @returns {boolean} Returns `true` if all members of the `values` param are empty, `false` otherwise\n */\nexport function areEmptyObjects<T>(...values: T[]): boolean {\n return values.every(isEmptyObject)\n}\n\n/**\n * Checks if `key` is a direct property of `value`\n *\n * @param {unknown} value `object` potentially containing property\n * @param {string} key property key\n * @returns whether `key` param is a property of the `obj` param\n */\nexport function has(value: unknown, key: string): boolean {\n return value != null && Object.hasOwn(value, key)\n}\n\n/**\n * Does an ordering and shallow comparison of each array value,\n * plus a value equality check for empty objects and arrays.\n */\nexport function areSelectorDepsEqual<T>(currentDeps: T[], nextDeps: T[]): boolean {\n if (currentDeps.length !== nextDeps.length) {\n return false\n }\n return currentDeps.every((currentDep, index) => {\n const nextDep = nextDeps[index]\n\n if (areEmptyArrays(currentDep, nextDep) || areEmptyObjects(currentDep, nextDep)) {\n return true\n }\n\n return currentDep === nextDep\n })\n}\n\nexport const getComparator = (selector: UseAuthenticatorSelector): Comparator => {\n return (currentFacade, nextFacade) => {\n const currentSelectorDeps = selector(currentFacade)\n const nextSelectorDeps = selector(nextFacade)\n\n // Shallow compare the array values\n return areSelectorDepsEqual(currentSelectorDeps, nextSelectorDeps)\n }\n}\n","import { useSelector } from '@xstate/react'\nimport { useContext } from 'react'\nimport { AuthenticatorContext } from '../context'\nimport { getSendEventAliases, getServiceContextFacade } from './facade'\nimport type { UseAuthenticator, UseAuthenticatorSelector } from './types'\nimport { getComparator } from './utils'\n\nconst defaultComparator = (): false => false\n\nexport const useAuthenticator = (selector?: UseAuthenticatorSelector): UseAuthenticator => {\n const context = useContext(AuthenticatorContext)\n\n if (!context) {\n throw new Error('`useAuthenticator` must be used inside an `AuthenticatorProvider`.')\n }\n\n const { actor } = context\n const { send } = actor\n\n const comparator = selector ? getComparator(selector) : defaultComparator\n\n return useSelector(\n actor,\n (snapshot) => ({\n ...getSendEventAliases(send),\n ...getServiceContextFacade(snapshot),\n }),\n comparator,\n )\n}\n","/*\n * Copyright 2017 - 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * (C) 2025 GAHOJIN, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n */\n\nimport type {\n AuthUser,\n CodeDeliveryDetails,\n ConfirmResetPasswordInput,\n ConfirmSignInInput,\n ConfirmSignInOutput,\n ConfirmSignUpInput,\n ConfirmSignUpOutput,\n ConfirmUserAttributeInput,\n FetchUserAttributesOutput,\n ResendSignUpCodeInput,\n ResendSignUpCodeOutput,\n ResetPasswordInput,\n ResetPasswordOutput,\n SendUserAttributeVerificationCodeInput,\n SendUserAttributeVerificationCodeOutput,\n SignInInput,\n SignInOutput,\n SignInWithRedirectInput,\n SignOutInput,\n SignUpInput,\n SignUpOutput,\n UserAttributeKey,\n} from '@aws-amplify/auth'\n\nexport type AuthMFAType = 'SMS' | 'TOTP' | 'EMAIL'\nexport type AuthAllowedMFATypes = AuthMFAType[]\n\nexport const FederatedIdentityProviders = {\n Apple: 'Apple',\n Amazon: 'Amazon',\n Facebook: 'Facebook',\n Google: 'Google',\n} as const\nexport type FederatedIdentityProviders = (typeof FederatedIdentityProviders)[keyof typeof FederatedIdentityProviders]\n\n/**\n * Cognito user contact method types that have not been verified as valid\n */\nexport const unverifiedContactMethodTypes = ['email', 'phone_number'] as const\nexport type UnverifiedContactMethodType = (typeof unverifiedContactMethodTypes)[number]\n\n/**\n * Authenticator routes that can be directly navigated to by user interaction.\n */\nexport type NavigableRoute = 'signIn' | 'signUp' | 'forgotPassword' | 'signOut'\nexport type InitialRoute = 'signIn' | 'signUp' | 'forgotPassword'\n\nexport type AuthTOTPSetupDetails = {\n sharedSecret: string\n getSetupUri: (appName: string, accountName?: string) => URL\n}\n\nexport type AuthEventTypes =\n | 'FEDERATED_SIGN_IN'\n | 'RESEND'\n | 'FORGOT_PASSWORD'\n | 'AUTO_SIGN_IN_FAILURE'\n | 'SIGN_IN_WITH_REDIRECT'\n | 'SIGN_IN'\n | 'SIGN_OUT'\n | 'SIGN_UP'\n | 'SUBMIT'\n | 'SKIP'\n | 'INIT'\n | 'TOKEN_REFRESH'\n\n// biome-ignore lint/suspicious/noExplicitAny: イベントデータの型は定義出来ない\nexport type AuthEventData = Record<PropertyKey, any>\n\nexport type AuthEvent = {\n type: AuthEventTypes\n data?: AuthEventData\n input?: ActorDoneData\n output?: AuthEventData\n error?: Error\n actorId?: string\n}\n\nexport type ActorDoneData = {\n codeDeliveryDetails?: CodeDeliveryDetails<UserAttributeKey>\n missingAttributes?: string[]\n remoteError?: string\n step: Step\n totpSecretCode?: string\n username?: string\n unverifiedUserAttributes?: UnverifiedUserAttributes\n allowedMfaTypes?: AuthMFAType[]\n}\n\nexport type AuthContext = {\n user?: AuthUser\n config?: {\n initialState?: 'signIn' | 'signUp' | 'forgotPassword'\n }\n // data returned from actors when they finish and reach their final state\n actorDoneData?: ActorDoneData\n}\n\nexport type InitialStep = 'FORGOT_PASSWORD' | 'SIGN_IN' | 'SIGN_UP'\n\nexport type SignInStep =\n | 'CONFIRM_SIGN_IN_WITH_EMAIL_CODE'\n | 'CONFIRM_SIGN_IN_WITH_SMS_CODE'\n | 'CONFIRM_SIGN_IN_WITH_TOTP_CODE'\n | 'CONFIRM_SIGN_IN_WITH_NEW_PASSWORD_REQUIRED'\n | 'CONFIRM_SIGN_IN_WITH_PASSWORD'\n | 'CONFIRM_SIGN_UP'\n | 'CONTINUE_SIGN_IN_WITH_TOTP_SETUP'\n | 'CONTINUE_SIGN_IN_WITH_EMAIL_SETUP'\n | 'CONTINUE_SIGN_IN_WITH_MFA_SETUP_SELECTION'\n | 'CONTINUE_SIGN_IN_WITH_MFA_SELECTION'\n | 'CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE'\n | 'CONTINUE_SIGN_IN_WITH_FIRST_FACTOR_SELECTION'\n | 'RESET_PASSWORD'\n | 'SIGN_IN_COMPLETE' // 'DONE'\n\nexport type ResetPasswordStep = 'CONFIRM_RESET_PASSWORD_WITH_CODE' | 'RESET_PASSWORD_COMPLETE' // 'DONE'\n\nexport type SignUpStep = 'CONFIRM_SIGN_UP' | 'COMPLETE_AUTO_SIGN_IN' | 'SIGN_UP_COMPLETE' // 'DONE'\n\nexport type UserAttributeStep = 'SHOULD_CONFIRM_USER_ATTRIBUTE' | 'CONFIRM_ATTRIBUTE_WITH_CODE' | 'CONFIRM_ATTRIBUTE_COMPLETE' // 'DONE'\n\nexport type Step = InitialStep | SignInStep | SignUpStep | ResetPasswordStep | UserAttributeStep\n\ntype BaseContext = {\n missingAttributes?: string[]\n remoteError?: string\n step: Step\n totpSecretCode?: string\n unverifiedUserAttributes?: UnverifiedUserAttributes\n allowedMfaTypes?: AuthMFAType[]\n\n // kept in memory for submission to relevnat APIs\n username?: string\n selectedUserAttribute?: string\n\n // retrieved from the Auth module on sign in,\n // cleared on sign out\n user?: AuthUser\n}\n\nexport type ResetPasswordContext = BaseContext & ActorDoneData\nexport type SignInContext = BaseContext & ActorDoneData\nexport type SignUpContext = BaseContext & ActorDoneData\nexport type VerifyUserContext = BaseContext & ActorDoneData\nexport type SignOutContext = Pick<BaseContext, 'user'>\n\nexport type AuthActorContext = SignInContext | SignUpContext | ResetPasswordContext\n\nexport type Handlers = {\n getCurrentUser: () => Promise<AuthUser>\n fetchUserAttributes: () => Promise<FetchUserAttributesOutput>\n signIn: (input: SignInInput) => Promise<SignInOutput>\n signInWithRedirect: (input?: SignInWithRedirectInput) => Promise<void>\n signUp: (input: SignUpInput) => Promise<SignUpOutput>\n signOut: (input?: SignOutInput) => Promise<void>\n autoSignIn: () => Promise<SignInOutput>\n confirmSignIn: (input: ConfirmSignInInput) => Promise<ConfirmSignInOutput>\n confirmSignUp: (input: ConfirmSignUpInput) => Promise<ConfirmSignUpOutput>\n confirmResetPassword: (input: ConfirmResetPasswordInput) => Promise<void>\n confirmUserAttribute: (input: ConfirmUserAttributeInput) => Promise<void>\n resetPassword: (input: ResetPasswordInput) => Promise<ResetPasswordOutput>\n resendSignUpCode: (input: ResendSignUpCodeInput) => Promise<ResendSignUpCodeOutput>\n sendUserAttributeVerificationCode: (input: SendUserAttributeVerificationCodeInput) => Promise<SendUserAttributeVerificationCodeOutput>\n}\n\nexport type UnverifiedUserAttributes = Partial<Record<UnverifiedContactMethodType, string>>\n\nexport type AuthError = Error & {\n __type: string\n message?: string\n}\n","export const getTotpCodeURL = (issuer: string, username: string, secret: string): string => {\n return encodeURI(`otpauth://totp/${issuer}:${username}?secret=${secret}&issuer=${issuer}`)\n}\n"],"mappings":";;;;;;;;AAOA,MAAa,uBAAiE,cAA+C,KAAK;;;ACAlI,MAAM,oBAAoB,YAAkE;AAC1F,SAAQ,MAAM,YAAY,sBAAsB,MAAM,SAAS,QAAQ;;AAOzE,IAAA,iCAAgB,EAAE,SAAS,eAAmC;CAC5D,MAAM,UAAU,cAAc,2BAA2B,QAAQ,EAAE,CAAC,QAAQ,CAAC;CAG7E,MAAM,iBAAiB,WAAW,qBAAqB;CACvD,MAAM,KAAK,SAAS,SAAS,QAAQ;CACrC,MAAM,QAAQ,cAAc,kBAAkB,EAAE,OAAO,EAAE,CAAC,gBAAgB,MAAM,CAAC;CAEjF,MAAM,EAAE,OAAO,gBAAgB;AAE/B,iBAAgB;AACd,SAAO,gBAAgB,aAAa,iBAAiB,QAAQ,CAAC;IAC7D,CAAC,aAAa,QAAQ,CAAC;AAE1B,QAAO,oBAAC,qBAAqB,UAAtB;EAAsC;EAAQ;EAAyC,CAAA;;;;ACHhG,MAAa,WAAW,aAAoC;CAC1D,MAAM,CAAC,QAAQ,aAAa,SAAwB,EAClD,WAAW,MACZ,CAAC;CAEF,MAAM,mBAAmB,kBAAkB;AAEzC,aAAW,UAAU;GAAE,GAAG;GAAM,WAAW;GAAM,EAAE;AAEnD,GAAM,UAAU,kBAAkB,iBAAiB,CAChD,MAAM,SAAS,UAAU;GAAE;GAAM,WAAW;GAAO,CAAC,CAAC,CACrD,OAAO,MAAM,UAAU;GAAE,OAAO;GAAY,WAAW;GAAO,CAAC,CAAC;IAClE,CAAC,UAAU,eAAe,CAAC;CAE9B,MAAM,aAA0B,aAC7B,EAAE,cAAc;AACf,UAAQ,QAAQ,OAAhB;GAEE,KAAK;GACL,KAAK;GACL,K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OAClC,QAAO;AAET,QAAO,YAAY,OAAO,YAAY,UAAU;EAC9C,MAAM,UAAU,SAAS;AAEzB,MAAI,eAAe,YAAY,QAAQ,IAAI,gBAAgB,YAAY,QAAQ,CAC7E,QAAO;AAGT,SAAO,eAAe;GACtB;;AAGJ,MAAa,iBAAiB,aAAmD;AAC/E,SAAQ,eAAe,eAAe;AAKpC,SAAO,qBAJqB,SAAS,cAAc,EAC1B,SAAS,WAAW,CAGqB;;;;;ACvKtE,MAAM,0BAAiC;AAEvC,MAAa,oBAAoB,aAA0D;CACzF,MAAM,UAAU,WAAW,qBAAqB;AAEhD,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,qEAAqE;CAGvF,MAAM,EAAE,UAAU;CAClB,MAAM,EAAE,SAAS;AAIjB,QAAO,YACL,QACC,cAAc;EACb,GAAG,oBAAoB,KAAK;EAC5B,GAAG,wBAAwB,SAAS;EACrC,GAPgB,WAAW,cAAc,SAAS,GAAG,kBASvD;;;;ACWH,MAAa,6BAA6B;CACxC,OAAO;CACP,QAAQ;CACR,UAAU;CACV,QAAQ;CACT;;;;AAMD,MAAa,+BAA+B,CAAC,SAAS,eAAe;;;AClDrE,MAAa,kBAAkB,QAAgB,UAAkB,WAA2B;AAC1F,QAAO,UAAU,kBAAkB,OAAO,GAAG,SAAS,UAAU,OAAO,UAAU,SAAS"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { assign, fromPromise, sendParent, setup } from "xstate";
|
|
1
|
+
import { assign, forwardTo, fromPromise, sendParent, setup } from "xstate";
|
|
2
2
|
import { autoSignIn, confirmResetPassword, confirmSignIn, confirmSignUp, confirmUserAttribute, fetchUserAttributes, getCurrentUser, resendSignUpCode, resetPassword, sendUserAttributeVerificationCode, signIn, signInWithRedirect, signOut, signUp } from "@aws-amplify/auth";
|
|
3
|
-
|
|
4
3
|
//#region src/machines/actions.ts
|
|
5
4
|
const setTotpSecretCode = ({ event }) => {
|
|
6
5
|
const { sharedSecret } = event.output?.nextStep?.totpSetupDetails ?? {};
|
|
@@ -55,7 +54,6 @@ const setSignInActorDoneData = ({ event }) => {
|
|
|
55
54
|
allowedMfaTypes: output.allowedMfaTypes
|
|
56
55
|
};
|
|
57
56
|
};
|
|
58
|
-
|
|
59
57
|
//#endregion
|
|
60
58
|
//#region src/machines/guards.ts
|
|
61
59
|
const SIGN_IN_STEP_MFA_CONFIRMATION = [
|
|
@@ -128,7 +126,6 @@ const shouldVerifyAttribute = (event) => {
|
|
|
128
126
|
const isUserAlreadyConfirmed = (event) => {
|
|
129
127
|
return event.error?.message === "User is already confirmed.";
|
|
130
128
|
};
|
|
131
|
-
|
|
132
129
|
//#endregion
|
|
133
130
|
//#region src/machines/signIn/actor.ts
|
|
134
131
|
/**
|
|
@@ -388,7 +385,6 @@ const signInActor = (handlers, overridesContext) => {
|
|
|
388
385
|
output: ({ context }) => context
|
|
389
386
|
});
|
|
390
387
|
};
|
|
391
|
-
|
|
392
388
|
//#endregion
|
|
393
389
|
//#region src/machines/defaultHandlers.ts
|
|
394
390
|
const defaultHandlers = {
|
|
@@ -407,7 +403,6 @@ const defaultHandlers = {
|
|
|
407
403
|
resendSignUpCode,
|
|
408
404
|
sendUserAttributeVerificationCode
|
|
409
405
|
};
|
|
410
|
-
|
|
411
406
|
//#endregion
|
|
412
407
|
//#region src/machines/forgotPassword/actor.ts
|
|
413
408
|
/**
|
|
@@ -541,7 +536,6 @@ const forgotPasswordActor = (handlers, overridesContext) => {
|
|
|
541
536
|
output: ({ context }) => context
|
|
542
537
|
});
|
|
543
538
|
};
|
|
544
|
-
|
|
545
539
|
//#endregion
|
|
546
540
|
//#region src/machines/signOut/actor.ts
|
|
547
541
|
/**
|
|
@@ -570,7 +564,6 @@ const signOutActor = (handlers) => {
|
|
|
570
564
|
output: ({ context }) => context
|
|
571
565
|
});
|
|
572
566
|
};
|
|
573
|
-
|
|
574
567
|
//#endregion
|
|
575
568
|
//#region src/machines/signUp/actor.ts
|
|
576
569
|
/**
|
|
@@ -799,7 +792,6 @@ const signUpActor = (handlers, overridesContext) => {
|
|
|
799
792
|
output: ({ context }) => context
|
|
800
793
|
});
|
|
801
794
|
};
|
|
802
|
-
|
|
803
795
|
//#endregion
|
|
804
796
|
//#region src/machines/verifyUserAttributes/actor.ts
|
|
805
797
|
/**
|
|
@@ -917,7 +909,223 @@ const verifyUserAttributesActor = (handlers, overridesContext) => {
|
|
|
917
909
|
output: ({ context }) => context
|
|
918
910
|
});
|
|
919
911
|
};
|
|
920
|
-
|
|
921
912
|
//#endregion
|
|
922
|
-
|
|
923
|
-
|
|
913
|
+
//#region src/machines/index.ts
|
|
914
|
+
/**
|
|
915
|
+
* @internal
|
|
916
|
+
*/
|
|
917
|
+
const createAuthenticatorMachine = (options) => {
|
|
918
|
+
const { handlers: customHandlers, ...config } = options ?? {};
|
|
919
|
+
const handlers = {
|
|
920
|
+
...defaultHandlers,
|
|
921
|
+
...customHandlers
|
|
922
|
+
};
|
|
923
|
+
return setup({
|
|
924
|
+
types: {
|
|
925
|
+
context: {},
|
|
926
|
+
events: {}
|
|
927
|
+
},
|
|
928
|
+
guards: {
|
|
929
|
+
hasCompletedAttributeConfirmation: ({ event: { output } }) => hasCompletedAttributeConfirmation(output?.step),
|
|
930
|
+
hasUser: ({ context }) => !!context.user,
|
|
931
|
+
isInitialStateSignUp: ({ context }) => context.config?.initialState === "signUp",
|
|
932
|
+
isInitialStateResetPassword: ({ context }) => context.config?.initialState === "forgotPassword",
|
|
933
|
+
isConfirmSignUpStep: ({ event: { output } }) => isConfirmSignUpStep(output?.step),
|
|
934
|
+
isConfirmUserAttributeStep: ({ event: { output } }) => isConfirmUserAttributeStep(output?.step),
|
|
935
|
+
isShouldConfirmUserAttributeStep: ({ event: { output } }) => isShouldConfirmUserAttributeStep(output?.step),
|
|
936
|
+
isResetPasswordStep: ({ event: { output } }) => isResetPasswordStep(output?.step)
|
|
937
|
+
},
|
|
938
|
+
actors: {
|
|
939
|
+
getCurrentUser: fromPromise(() => handlers.getCurrentUser()),
|
|
940
|
+
invokeSignInActor: signInActor(handlers),
|
|
941
|
+
invokeSignUpActor: signUpActor(handlers),
|
|
942
|
+
invokeForgotPasswordActor: forgotPasswordActor(handlers),
|
|
943
|
+
invokeVerifyUserAttributesActor: verifyUserAttributesActor(handlers),
|
|
944
|
+
invokeSignOutActor: signOutActor(handlers)
|
|
945
|
+
},
|
|
946
|
+
actions: {
|
|
947
|
+
clearActorDoneData: assign({ actorDoneData: void 0 }),
|
|
948
|
+
clearUser: assign({ user: void 0 }),
|
|
949
|
+
forwardToActor: forwardTo("childActor"),
|
|
950
|
+
setUser: assign({ user: ({ event }) => event.output }),
|
|
951
|
+
setActorDoneData: assign({ actorDoneData: ({ event }) => event.output })
|
|
952
|
+
}
|
|
953
|
+
}).createMachine({
|
|
954
|
+
id: "authenticator",
|
|
955
|
+
initial: "idle",
|
|
956
|
+
context: {
|
|
957
|
+
config,
|
|
958
|
+
user: void 0
|
|
959
|
+
},
|
|
960
|
+
states: {
|
|
961
|
+
idle: { invoke: {
|
|
962
|
+
src: "getCurrentUser",
|
|
963
|
+
onDone: {
|
|
964
|
+
actions: "setUser",
|
|
965
|
+
target: "#authenticator.setup"
|
|
966
|
+
},
|
|
967
|
+
onError: { target: "#authenticator.setup" }
|
|
968
|
+
} },
|
|
969
|
+
setup: {
|
|
970
|
+
initial: "init",
|
|
971
|
+
states: { init: { always: [
|
|
972
|
+
{
|
|
973
|
+
guard: "hasUser",
|
|
974
|
+
target: "#authenticator.authenticated"
|
|
975
|
+
},
|
|
976
|
+
{
|
|
977
|
+
guard: "isInitialStateSignUp",
|
|
978
|
+
target: "#authenticator.signUpActor"
|
|
979
|
+
},
|
|
980
|
+
{
|
|
981
|
+
guard: "isInitialStateResetPassword",
|
|
982
|
+
target: "#authenticator.forgotPasswordActor"
|
|
983
|
+
},
|
|
984
|
+
{ target: "#authenticator.signInActor" }
|
|
985
|
+
] } }
|
|
986
|
+
},
|
|
987
|
+
getCurrentUser: { invoke: {
|
|
988
|
+
src: "getCurrentUser",
|
|
989
|
+
onDone: {
|
|
990
|
+
actions: "setUser",
|
|
991
|
+
target: "#authenticator.authenticated"
|
|
992
|
+
},
|
|
993
|
+
onError: { target: "setup" }
|
|
994
|
+
} },
|
|
995
|
+
signInActor: {
|
|
996
|
+
invoke: {
|
|
997
|
+
id: "childActor",
|
|
998
|
+
src: "invokeSignInActor",
|
|
999
|
+
input: ({ context }) => context.actorDoneData,
|
|
1000
|
+
onDone: [
|
|
1001
|
+
{
|
|
1002
|
+
guard: "hasCompletedAttributeConfirmation",
|
|
1003
|
+
target: "#authenticator.getCurrentUser"
|
|
1004
|
+
},
|
|
1005
|
+
{
|
|
1006
|
+
guard: "isShouldConfirmUserAttributeStep",
|
|
1007
|
+
actions: "setActorDoneData",
|
|
1008
|
+
target: "#authenticator.verifyUserAttributesActor"
|
|
1009
|
+
},
|
|
1010
|
+
{
|
|
1011
|
+
guard: "isResetPasswordStep",
|
|
1012
|
+
actions: "setActorDoneData",
|
|
1013
|
+
target: "#authenticator.forgotPasswordActor"
|
|
1014
|
+
},
|
|
1015
|
+
{
|
|
1016
|
+
guard: "isConfirmSignUpStep",
|
|
1017
|
+
actions: "setActorDoneData",
|
|
1018
|
+
target: "#authenticator.signUpActor"
|
|
1019
|
+
}
|
|
1020
|
+
]
|
|
1021
|
+
},
|
|
1022
|
+
entry: "clearActorDoneData",
|
|
1023
|
+
on: {
|
|
1024
|
+
FORGOT_PASSWORD: { target: "#authenticator.forgotPasswordActor" },
|
|
1025
|
+
SIGN_UP: { target: "#authenticator.signUpActor" },
|
|
1026
|
+
SIGN_IN: { actions: "forwardToActor" },
|
|
1027
|
+
FEDERATED_SIGN_IN: { actions: "forwardToActor" },
|
|
1028
|
+
SUBMIT: { actions: "forwardToActor" }
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
signUpActor: {
|
|
1032
|
+
invoke: {
|
|
1033
|
+
id: "childActor",
|
|
1034
|
+
src: "invokeSignUpActor",
|
|
1035
|
+
input: ({ context }) => context.actorDoneData,
|
|
1036
|
+
onDone: [
|
|
1037
|
+
{
|
|
1038
|
+
guard: "hasCompletedAttributeConfirmation",
|
|
1039
|
+
actions: "clearActorDoneData",
|
|
1040
|
+
target: "#authenticator.getCurrentUser"
|
|
1041
|
+
},
|
|
1042
|
+
{
|
|
1043
|
+
guard: "isShouldConfirmUserAttributeStep",
|
|
1044
|
+
actions: "setActorDoneData",
|
|
1045
|
+
target: "#authenticator.verifyUserAttributesActor"
|
|
1046
|
+
},
|
|
1047
|
+
{
|
|
1048
|
+
guard: "isConfirmUserAttributeStep",
|
|
1049
|
+
actions: "clearActorDoneData",
|
|
1050
|
+
target: "#authenticator.verifyUserAttributesActor"
|
|
1051
|
+
},
|
|
1052
|
+
{
|
|
1053
|
+
actions: "setActorDoneData",
|
|
1054
|
+
target: "#authenticator.signInActor"
|
|
1055
|
+
}
|
|
1056
|
+
]
|
|
1057
|
+
},
|
|
1058
|
+
on: {
|
|
1059
|
+
SIGN_IN: { target: "#authenticator.signInActor" },
|
|
1060
|
+
FEDERATED_SIGN_IN: { actions: "forwardToActor" },
|
|
1061
|
+
RESEND: { actions: "forwardToActor" },
|
|
1062
|
+
SUBMIT: { actions: "forwardToActor" }
|
|
1063
|
+
}
|
|
1064
|
+
},
|
|
1065
|
+
forgotPasswordActor: {
|
|
1066
|
+
invoke: {
|
|
1067
|
+
id: "childActor",
|
|
1068
|
+
src: "invokeForgotPasswordActor",
|
|
1069
|
+
input: ({ context }) => context.actorDoneData,
|
|
1070
|
+
onDone: { target: "#authenticator.signInActor" }
|
|
1071
|
+
},
|
|
1072
|
+
exit: "clearActorDoneData",
|
|
1073
|
+
on: {
|
|
1074
|
+
SIGN_IN: { target: "#authenticator.signInActor" },
|
|
1075
|
+
RESEND: { actions: "forwardToActor" },
|
|
1076
|
+
SUBMIT: { actions: "forwardToActor" }
|
|
1077
|
+
}
|
|
1078
|
+
},
|
|
1079
|
+
verifyUserAttributesActor: {
|
|
1080
|
+
invoke: {
|
|
1081
|
+
id: "childActor",
|
|
1082
|
+
src: "invokeVerifyUserAttributesActor",
|
|
1083
|
+
input: ({ context }) => context.actorDoneData,
|
|
1084
|
+
onDone: {
|
|
1085
|
+
actions: "setActorDoneData",
|
|
1086
|
+
target: "#authenticator.getCurrentUser"
|
|
1087
|
+
}
|
|
1088
|
+
},
|
|
1089
|
+
on: {
|
|
1090
|
+
SKIP: { actions: "forwardToActor" },
|
|
1091
|
+
RESEND: { actions: "forwardToActor" },
|
|
1092
|
+
SUBMIT: { actions: "forwardToActor" }
|
|
1093
|
+
}
|
|
1094
|
+
},
|
|
1095
|
+
authenticated: {
|
|
1096
|
+
initial: "idle",
|
|
1097
|
+
on: { SIGN_OUT: { target: "#authenticator.signOut" } },
|
|
1098
|
+
states: {
|
|
1099
|
+
idle: { on: { TOKEN_REFRESH: { target: "refreshUser" } } },
|
|
1100
|
+
refreshUser: { invoke: {
|
|
1101
|
+
src: "getCurrentUser",
|
|
1102
|
+
onDone: {
|
|
1103
|
+
actions: "setUser",
|
|
1104
|
+
target: "idle"
|
|
1105
|
+
},
|
|
1106
|
+
onError: { target: "#authenticator.signOut" }
|
|
1107
|
+
} }
|
|
1108
|
+
}
|
|
1109
|
+
},
|
|
1110
|
+
signOut: {
|
|
1111
|
+
invoke: {
|
|
1112
|
+
id: "childActor",
|
|
1113
|
+
src: "invokeSignOutActor",
|
|
1114
|
+
onDone: {
|
|
1115
|
+
actions: "clearUser",
|
|
1116
|
+
target: "#authenticator.setup"
|
|
1117
|
+
}
|
|
1118
|
+
},
|
|
1119
|
+
exit: "clearActorDoneData"
|
|
1120
|
+
}
|
|
1121
|
+
},
|
|
1122
|
+
on: {
|
|
1123
|
+
CHILD_CHANGED: { actions: assign(({ context }) => context) },
|
|
1124
|
+
SIGN_IN_WITH_REDIRECT: { target: "#authenticator.getCurrentUser" }
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
};
|
|
1128
|
+
//#endregion
|
|
1129
|
+
export { createAuthenticatorMachine as t };
|
|
1130
|
+
|
|
1131
|
+
//# sourceMappingURL=machines-BRfb3dTb.js.map
|