@saasquatch/mint-components 1.8.5-20 → 1.8.5-21

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.
@@ -18,9 +18,9 @@ function setSubmitted(submitted) {
18
18
  window[SUBMITTED_CONTEXT] = submitted;
19
19
  }
20
20
  function usePortalVerifyEmail({ nextPage, failedPage, verifySuccessText, verifyEmailText, verifyInvalidText, networkErrorMessage, continueText, }) {
21
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
21
+ var _b, _c, _d, _e, _f, _g, _h, _j;
22
22
  const submitted = window[SUBMITTED_CONTEXT];
23
- // const userIdent = useUserIdentity();
23
+ const userIdent = index_module.Q();
24
24
  const [verificationError, setVerificationError] = stencilHooks_module.useState(null);
25
25
  const [success, setSuccess] = stencilHooks_module.useState(false);
26
26
  const [request, { loading, data, errors }] = index_module.an();
@@ -31,18 +31,8 @@ function usePortalVerifyEmail({ nextPage, failedPage, verifySuccessText, verifyE
31
31
  // derived from useMutation in component boilerplate initialState
32
32
  const disableContinue = data === undefined && errors === undefined && !!oobCode;
33
33
  // if logged out, userIdent?.managedIdentity?.emailVerified will be falsey, even if verification was successful
34
- const userIdentContext = localStorage.getItem("sq:user-identity");
35
- const userIdent = getUserIdent(userIdentContext);
36
- const email = (_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.email;
34
+ const hasContext = localStorage.getItem("sq:user-identity");
37
35
  const verified = !!(((_b = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _b === void 0 ? void 0 : _b.emailVerified) || (data === null || data === void 0 ? void 0 : data.verifyManagedIdentityEmail.success));
38
- function getUserIdent(context) {
39
- try {
40
- return JSON.parse(context);
41
- }
42
- catch {
43
- return undefined;
44
- }
45
- }
46
36
  const failed = () => {
47
37
  return index_module.$n.push({
48
38
  pathname: failedPage,
@@ -54,51 +44,61 @@ function usePortalVerifyEmail({ nextPage, failedPage, verifySuccessText, verifyE
54
44
  const url = utils.sanitizeUrlPath(nextPageOverride || nextPage);
55
45
  index_module.$n.push(url.href);
56
46
  };
57
- const logout = () => {
58
- console.debug("LOGOUT");
59
- setTimeout(() => {
60
- gotoNextPage();
61
- index_module.setUserIdentity(undefined);
62
- setSubmitted(false);
63
- }, 3000);
64
- };
65
- const submit = async () => {
47
+ console.log({
48
+ hasContext,
49
+ userIdent,
50
+ data,
51
+ submitted,
52
+ verified,
53
+ verificationError,
54
+ success,
55
+ });
56
+ stencilHooks_module.useEffect(() => {
57
+ const check = async () => {
58
+ var _a;
59
+ const response = await request({ oobCode });
60
+ if (response instanceof Error ||
61
+ !((_a = response === null || response === void 0 ? void 0 : response.verifyManagedIdentityEmail) === null || _a === void 0 ? void 0 : _a.success)) {
62
+ console.debug("set verification error");
63
+ setVerificationError({ message: true });
64
+ }
65
+ else {
66
+ console.debug("set success: true");
67
+ setSuccess(true);
68
+ }
69
+ console.debug("SUBMITTED", response);
70
+ setSubmitted(true);
71
+ };
72
+ if (!submitted)
73
+ check();
74
+ }, [submitted]);
75
+ stencilHooks_module.useEffect(() => {
66
76
  var _a, _b;
67
- setSubmitted(true);
68
- const response = await request({ oobCode });
69
- if (response instanceof Error ||
70
- !((_a = response === null || response === void 0 ? void 0 : response.verifyManagedIdentityEmail) === null || _a === void 0 ? void 0 : _a.success)) {
71
- setVerificationError({ message: true });
72
- }
73
- else if ((_b = response === null || response === void 0 ? void 0 : response.verifyManagedIdentityEmail) === null || _b === void 0 ? void 0 : _b.success) {
74
- setSuccess(true);
75
- }
76
- if (email && email !== oobEmail) {
77
- console.debug("email mismatch", { response });
78
- logout();
77
+ if (!submitted)
79
78
  return;
79
+ if (!verificationError &&
80
+ // oob is valid + matching email OR logged in user is verified
81
+ ((success && ((_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.email) === oobEmail) || verified)) {
82
+ console.log("LOGGING IN", success, verified, verificationError);
83
+ setTimeout(gotoNextPage, 3000);
80
84
  }
81
- console.debug("SUBMITTED", response);
82
- };
83
- stencilHooks_module.useEffect(() => {
84
- console.log({ verified, userIdent });
85
- if (verified) {
86
- setSuccess(true);
87
- setTimeout(() => {
88
- gotoNextPage();
85
+ else {
86
+ console.log("LOGGING OUT", success, verified, verificationError);
87
+ if ((_b = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _b === void 0 ? void 0 : _b.email) {
89
88
  index_module.setUserIdentity(undefined);
90
- setSubmitted(false);
91
- }, 3000);
89
+ setTimeout(gotoNextPage, 3000);
90
+ }
92
91
  }
93
- else if (!data && !submitted && oobCode)
94
- submit();
95
- }, [verified, submitted, data, userIdent]);
96
- // console.log({ hasContext, userIdent, data, submitted, verified, errors });
97
- // useEffect(() => {
98
- // if (errors && !verified) setVerificationError(errors);
99
- // }, [errors, verified]);
92
+ }, [verified, verificationError, success, submitted, userIdent]);
93
+ stencilHooks_module.useEffect(() => {
94
+ if (errors)
95
+ setVerificationError(errors);
96
+ }, [errors, setVerificationError]);
100
97
  // useEffect(() => {
101
- // if (!data && !submitted && oobCode) submit();
98
+ // if (!data && !submitted && oobCode) {
99
+ // submit();
100
+ // return;
101
+ // }
102
102
  // // verification successful but user in context is not verified
103
103
  // // or mismatch between logged in user and user associated with oobCode
104
104
  // if (submitted) {
@@ -7605,7 +7605,7 @@ const PortalResetPassword = /*#__PURE__*/Object.freeze({
7605
7605
  CodeValidating: CodeValidating
7606
7606
  });
7607
7607
 
7608
- const scenario$9 = "@author:derek\n@owner:ian\nFeature: Verify Email\n\n Background: A user is on the email verification page\n Given a user who has been redirected to the email verification page\n\n @motivating\n Scenario: Verifying your email takes you to the portal login page\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email is validated\n Then a button that says \"Continue\" appears\n When they click \"Continue\"\n Then they are redirected to login\n\n @motivating\n Scenario: Users are automatically redirected if they dont click \"Continue\"\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email is validated\n Then a button that says \"Continue\" appears\n When they wait 5 seconds\n Then they are redirected to login\n\n @motivating\n Scenario: Users are notified if verifying their email has failed\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email fails to be validated\n Then an banner is shown stating that an error occured\n\n @motivating\n Scenario Outline: Users cannot verify their email with an invalid or missing oob code\n Given a user has a <oobCode> as a url query parameter\n And the component <mayHave> \"failed-page\" with <value>\n Then they see an error message saying that their verification code is invalid/expired\n When they click \"Continue\"\n Then they are redirected to <redirectPath>\n Examples:\n | oobCode | mayHave | value | redirectPath |\n | invalid oob code | doesn't have | N/A | / |\n | non existant oob code | doesn't have | N/A | / |\n | invalid oob code | has | /login | /login |\n | non existant oob code | has | /login | /login |\n\n @motivating\n Scenario: Users are redirected to \"/\" by default\n Given the component does not have prop \"nextPage\"\n And the users url does not contain a \"nextPage\" query parameter\n And a user has verified their email\n When they click \"Continue\"\n Then they are redirected to \"/\"\n\n @motivating\n Scenario: Custom redirection can be configured\n Given the component has prop \"nextPage\" with value \"/activity\"\n And the users url does not contain a \"nextPage\" query parameter\n And a user has verified their email\n When they click \"Continue\"\n Then they are redirected to \"/activity\"\n\n @motivating\n Scenario Outline: Users are redirected to the value of the nextPage url parameter if it exists\n Given the component <mayHave> prop \"nextPage\" with <nextPageValue>\n And the users url contains a \"nextPage\" query paramater with <nextPageParamValue>\n And the user has verified their email\n When they click \"Continue\"\n Then they are redirected to <nextPageParamValue>\n Examples:\n | mayHave | nextPageValue | nextPageParamValue |\n | has | /dashboard | /activity |\n | does not have | N/A | /activity |\n\n @motivating\n Scenario Outline: Users are redirected to the value of the nextPage url parameter as if it were a relative path\n Given the component is loaded at <currentUrl>\n And the user has verified their email\n When they click \"Continue\"\n And they are redirected to <url>\n Examples:\n | currentUrl | url |\n | https://www.example.com?nextPage=./activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=/activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=www.google.com | https://www.example.com/www.google.com |\n | https://www.example.com?nextPage=//foo.com | https://www.example.com/ |\n | https://www.example.com?nextPage=https://malicious.example.com | https://www.example.com/ |\n | http://www.example.com/nest/page?oob=123&other&nextPage=activity#heading-1 | http://www.example.com/activity |\n | https://www.example.com?nextPage=activity?foo=bar | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar#hash | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar%23hash | https://www.example.com/activity?foo=bar#hash |\n | https://www.example.com:1337?nextPage=activity | https://www.example.com:1337/activity |\n | http://1.1.1.1:1111?nextPage=activity | http://1.1.1.1:1111/activity |\n\n @landmine\n Scenario Outline: Username and password are not persisted on redirects\n Given the component is loaded at <currentUrl>\n And the user has verified their email\n When they click \"Continue\"\n And they are redirected to <url>\n Examples:\n | currentUrl | url |\n | https://user:pass@www.example.com:444?nextPage=activity | https://www.example.com:444/activity |\n\n\n @minutia\n Scenario Outline: Users may be logged in or logged out depending on the verified status and logged in email\n Given an oobCode with email <oobCodeEmail> as a url query parameter\n And the user is logged in as <loggedInEmail>\n And the logged in user <isVerified>\n When the oobCode is submitted\n And the oobCode <isValid>\n Then the <submitState> screen is shown\n And after 3 seconds pass\n Then the user is redirected to <redirect>\n Examples:\n | oobCodeEmail | loggedInEmail | isVerified | isValid | submitState | redirect |\n | user1@example.com | N/A | false | is valid | success | /login |\n | user1@example.com | N/A | false | is not valid | error | /login |\n | user1@example.com | user1@example.com | false | is valid | success | /activity |\n | user1@example.com | user1@example.com | false | is not valid | error | N/A |\n | user1@example.com | user2@example.com | false | is valid | success | /login |\n | user1@example.com | user2@example.com | false | is not valid | error | /login |\n | user1@example.com | user1@example.com | true | is valid | success | /activity |\n | user1@example.com | user1@example.com | true | is not valid | success | /activity |\n | user1@example.com | user2@example.com | true | is not valid | error | /login |\n | N/A | N/A | false | is not valid | error | N/A |\n";
7608
+ const scenario$9 = "@author:derek\n@owner:ian\nFeature: Verify Email\n\n Background: A user is on the email verification page\n Given a user who has been redirected to the email verification page\n\n @motivating\n Scenario: Verifying your email takes you to the portal login page\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email is validated\n Then a button that says \"Continue\" appears\n When they click \"Continue\"\n Then they are redirected to login\n\n @motivating\n Scenario: Users are automatically redirected if they dont click \"Continue\"\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email is validated\n Then a button that says \"Continue\" appears\n When they wait 5 seconds\n Then they are redirected to login\n\n @motivating\n Scenario: Users are notified if verifying their email has failed\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email fails to be validated\n Then an banner is shown stating that an error occured\n\n @motivating\n Scenario Outline: Users cannot verify their email with an invalid or missing oob code\n Given a user has a <oobCode> as a url query parameter\n And the component <mayHave> \"failed-page\" with <value>\n Then they see an error message saying that their verification code is invalid/expired\n When they click \"Continue\"\n Then they are redirected to <redirectPath>\n Examples:\n | oobCode | mayHave | value | redirectPath |\n | invalid oob code | doesn't have | N/A | / |\n | non existant oob code | doesn't have | N/A | / |\n | invalid oob code | has | /login | /login |\n | non existant oob code | has | /login | /login |\n\n @motivating\n Scenario: Users are redirected to \"/\" by default\n Given the component does not have prop \"nextPage\"\n And the users url does not contain a \"nextPage\" query parameter\n And a user has verified their email\n When they click \"Continue\"\n Then they are redirected to \"/\"\n\n @motivating\n Scenario: Custom redirection can be configured\n Given the component has prop \"nextPage\" with value \"/activity\"\n And the users url does not contain a \"nextPage\" query parameter\n And a user has verified their email\n When they click \"Continue\"\n Then they are redirected to \"/activity\"\n\n @motivating\n Scenario Outline: Users are redirected to the value of the nextPage url parameter if it exists\n Given the component <mayHave> prop \"nextPage\" with <nextPageValue>\n And the users url contains a \"nextPage\" query paramater with <nextPageParamValue>\n And the user has verified their email\n When they click \"Continue\"\n Then they are redirected to <nextPageParamValue>\n Examples:\n | mayHave | nextPageValue | nextPageParamValue |\n | has | /dashboard | /activity |\n | does not have | N/A | /activity |\n\n @motivating\n Scenario Outline: Users are redirected to the value of the nextPage url parameter as if it were a relative path\n Given the component is loaded at <currentUrl>\n And the user has verified their email\n When they click \"Continue\"\n And they are redirected to <url>\n Examples:\n | currentUrl | url |\n | https://www.example.com?nextPage=./activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=/activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=www.google.com | https://www.example.com/www.google.com |\n | https://www.example.com?nextPage=//foo.com | https://www.example.com/ |\n | https://www.example.com?nextPage=https://malicious.example.com | https://www.example.com/ |\n | http://www.example.com/nest/page?oob=123&other&nextPage=activity#heading-1 | http://www.example.com/activity |\n | https://www.example.com?nextPage=activity?foo=bar | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar#hash | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar%23hash | https://www.example.com/activity?foo=bar#hash |\n | https://www.example.com:1337?nextPage=activity | https://www.example.com:1337/activity |\n | http://1.1.1.1:1111?nextPage=activity | http://1.1.1.1:1111/activity |\n\n @landmine\n Scenario Outline: Username and password are not persisted on redirects\n Given the component is loaded at <currentUrl>\n And the user has verified their email\n When they click \"Continue\"\n And they are redirected to <url>\n Examples:\n | currentUrl | url |\n | https://user:pass@www.example.com:444?nextPage=activity | https://www.example.com:444/activity |\n\n\n @minutia\n Scenario Outline: Users may be logged in or logged out depending on the verified status and logged in email\n Given an oobCode with email <oobCodeEmail> as a url query parameter\n And the user is logged in as <loggedInEmail>\n And the logged in user <isVerified>\n When the oobCode is submitted\n And the oobCode <isValid>\n Then the <submitState> screen is shown\n And after 3 seconds pass\n Then the user is redirected to <redirect>\n Examples:\n | oobCodeEmail | loggedInEmail | isVerified | isValid | submitState | redirect |\n | user1@example.com | N/A | false | is valid | success | /login |\n | user1@example.com | N/A | false | is not valid | error | /login |\n | user1@example.com | user1@example.com | false | is valid | success | /activity |\n | user1@example.com | user1@example.com | false | is not valid | error | N/A |\n | user1@example.com | user2@example.com | false | is valid | success | /login |\n | user1@example.com | user2@example.com | false | is not valid | error | /login |\n | user1@example.com | user1@example.com | true | is valid | success | /activity |\n | user1@example.com | user1@example.com | true | is not valid | success | /activity |\n | user1@example.com | user2@example.com | true | is not valid | error | /login |\n | N/A | N/A | false | is not valid | error | N/A |\n";
7609
7609
 
7610
7610
  const PortalVerifyEmail_stories = {
7611
7611
  title: "Components/Microsite Verify Email",
@@ -1,4 +1,4 @@
1
- import { navigation, setUserIdentity, useVerifyEmailMutation, } from "@saasquatch/component-boilerplate";
1
+ import { navigation, setUserIdentity, useUserIdentity, useVerifyEmailMutation, } from "@saasquatch/component-boilerplate";
2
2
  import { useEffect, useState } from "@saasquatch/universal-hooks";
3
3
  import { sanitizeUrlPath } from "../../utils/utils";
4
4
  const SUBMITTED_CONTEXT = "sq:verify-submitted";
@@ -9,9 +9,10 @@ function setSubmitted(submitted) {
9
9
  export function usePortalVerifyEmail({ nextPage, failedPage, verifySuccessText, verifyEmailText, verifyInvalidText, networkErrorMessage, continueText, }) {
10
10
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
11
11
  const submitted = window[SUBMITTED_CONTEXT];
12
- // const userIdent = useUserIdentity();
12
+ const userIdent = useUserIdentity();
13
13
  const [verificationError, setVerificationError] = useState(null);
14
14
  const [success, setSuccess] = useState(false);
15
+ const email = (_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.email;
15
16
  const [request, { loading, data, errors }] = useVerifyEmailMutation();
16
17
  const urlParams = new URLSearchParams(navigation.location.search);
17
18
  const oobCode = urlParams.get("oobCode");
@@ -20,18 +21,8 @@ export function usePortalVerifyEmail({ nextPage, failedPage, verifySuccessText,
20
21
  // derived from useMutation in component boilerplate initialState
21
22
  const disableContinue = data === undefined && errors === undefined && !!oobCode;
22
23
  // if logged out, userIdent?.managedIdentity?.emailVerified will be falsey, even if verification was successful
23
- const userIdentContext = localStorage.getItem("sq:user-identity");
24
- const userIdent = getUserIdent(userIdentContext);
25
- const email = (_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.email;
24
+ const hasContext = localStorage.getItem("sq:user-identity");
26
25
  const verified = !!(((_b = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _b === void 0 ? void 0 : _b.emailVerified) || (data === null || data === void 0 ? void 0 : data.verifyManagedIdentityEmail.success));
27
- function getUserIdent(context) {
28
- try {
29
- return JSON.parse(context);
30
- }
31
- catch {
32
- return undefined;
33
- }
34
- }
35
26
  const failed = () => {
36
27
  return navigation.push({
37
28
  pathname: failedPage,
@@ -43,51 +34,61 @@ export function usePortalVerifyEmail({ nextPage, failedPage, verifySuccessText,
43
34
  const url = sanitizeUrlPath(nextPageOverride || nextPage);
44
35
  navigation.push(url.href);
45
36
  };
46
- const logout = () => {
47
- console.debug("LOGOUT");
48
- setTimeout(() => {
49
- gotoNextPage();
50
- setUserIdentity(undefined);
51
- setSubmitted(false);
52
- }, 3000);
53
- };
54
- const submit = async () => {
37
+ console.log({
38
+ hasContext,
39
+ userIdent,
40
+ data,
41
+ submitted,
42
+ verified,
43
+ verificationError,
44
+ success,
45
+ });
46
+ useEffect(() => {
47
+ const check = async () => {
48
+ var _a;
49
+ const response = await request({ oobCode });
50
+ if (response instanceof Error ||
51
+ !((_a = response === null || response === void 0 ? void 0 : response.verifyManagedIdentityEmail) === null || _a === void 0 ? void 0 : _a.success)) {
52
+ console.debug("set verification error");
53
+ setVerificationError({ message: true });
54
+ }
55
+ else {
56
+ console.debug("set success: true");
57
+ setSuccess(true);
58
+ }
59
+ console.debug("SUBMITTED", response);
60
+ setSubmitted(true);
61
+ };
62
+ if (!submitted)
63
+ check();
64
+ }, [submitted]);
65
+ useEffect(() => {
55
66
  var _a, _b;
56
- setSubmitted(true);
57
- const response = await request({ oobCode });
58
- if (response instanceof Error ||
59
- !((_a = response === null || response === void 0 ? void 0 : response.verifyManagedIdentityEmail) === null || _a === void 0 ? void 0 : _a.success)) {
60
- setVerificationError({ message: true });
61
- }
62
- else if ((_b = response === null || response === void 0 ? void 0 : response.verifyManagedIdentityEmail) === null || _b === void 0 ? void 0 : _b.success) {
63
- setSuccess(true);
64
- }
65
- if (email && email !== oobEmail) {
66
- console.debug("email mismatch", { response });
67
- logout();
67
+ if (!submitted)
68
68
  return;
69
+ if (!verificationError &&
70
+ // oob is valid + matching email OR logged in user is verified
71
+ ((success && ((_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.email) === oobEmail) || verified)) {
72
+ console.log("LOGGING IN", success, verified, verificationError);
73
+ setTimeout(gotoNextPage, 3000);
69
74
  }
70
- console.debug("SUBMITTED", response);
71
- };
72
- useEffect(() => {
73
- console.log({ verified, userIdent });
74
- if (verified) {
75
- setSuccess(true);
76
- setTimeout(() => {
77
- gotoNextPage();
75
+ else {
76
+ console.log("LOGGING OUT", success, verified, verificationError);
77
+ if ((_b = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _b === void 0 ? void 0 : _b.email) {
78
78
  setUserIdentity(undefined);
79
- setSubmitted(false);
80
- }, 3000);
79
+ setTimeout(gotoNextPage, 3000);
80
+ }
81
81
  }
82
- else if (!data && !submitted && oobCode)
83
- submit();
84
- }, [verified, submitted, data, userIdent]);
85
- // console.log({ hasContext, userIdent, data, submitted, verified, errors });
86
- // useEffect(() => {
87
- // if (errors && !verified) setVerificationError(errors);
88
- // }, [errors, verified]);
82
+ }, [verified, verificationError, success, submitted, userIdent]);
83
+ useEffect(() => {
84
+ if (errors)
85
+ setVerificationError(errors);
86
+ }, [errors, setVerificationError]);
89
87
  // useEffect(() => {
90
- // if (!data && !submitted && oobCode) submit();
88
+ // if (!data && !submitted && oobCode) {
89
+ // submit();
90
+ // return;
91
+ // }
91
92
  // // verification successful but user in context is not verified
92
93
  // // or mismatch between logged in user and user associated with oobCode
93
94
  // if (submitted) {
@@ -1,6 +1,6 @@
1
1
  import { r as registerInstance, h as h$1 } from './index-17b4da69.js';
2
2
  import { k as useState, f as useEffect, n as h } from './stencil-hooks.module-8032b139.js';
3
- import { j as an, $ as $n, b as setUserIdentity, i as isDemo } from './index.module-ba0ed7a8.js';
3
+ import { Q, j as an, $ as $n, b as setUserIdentity, i as isDemo } from './index.module-ba0ed7a8.js';
4
4
  import { c as cjs } from './cjs-bdfb4486.js';
5
5
  import './mixins-f60a614c.js';
6
6
  import './JSS-67b5cff8.js';
@@ -14,9 +14,9 @@ function setSubmitted(submitted) {
14
14
  window[SUBMITTED_CONTEXT] = submitted;
15
15
  }
16
16
  function usePortalVerifyEmail({ nextPage, failedPage, verifySuccessText, verifyEmailText, verifyInvalidText, networkErrorMessage, continueText, }) {
17
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
17
+ var _b, _c, _d, _e, _f, _g, _h, _j;
18
18
  const submitted = window[SUBMITTED_CONTEXT];
19
- // const userIdent = useUserIdentity();
19
+ const userIdent = Q();
20
20
  const [verificationError, setVerificationError] = useState(null);
21
21
  const [success, setSuccess] = useState(false);
22
22
  const [request, { loading, data, errors }] = an();
@@ -27,18 +27,8 @@ function usePortalVerifyEmail({ nextPage, failedPage, verifySuccessText, verifyE
27
27
  // derived from useMutation in component boilerplate initialState
28
28
  const disableContinue = data === undefined && errors === undefined && !!oobCode;
29
29
  // if logged out, userIdent?.managedIdentity?.emailVerified will be falsey, even if verification was successful
30
- const userIdentContext = localStorage.getItem("sq:user-identity");
31
- const userIdent = getUserIdent(userIdentContext);
32
- const email = (_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.email;
30
+ const hasContext = localStorage.getItem("sq:user-identity");
33
31
  const verified = !!(((_b = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _b === void 0 ? void 0 : _b.emailVerified) || (data === null || data === void 0 ? void 0 : data.verifyManagedIdentityEmail.success));
34
- function getUserIdent(context) {
35
- try {
36
- return JSON.parse(context);
37
- }
38
- catch {
39
- return undefined;
40
- }
41
- }
42
32
  const failed = () => {
43
33
  return $n.push({
44
34
  pathname: failedPage,
@@ -50,51 +40,61 @@ function usePortalVerifyEmail({ nextPage, failedPage, verifySuccessText, verifyE
50
40
  const url = sanitizeUrlPath(nextPageOverride || nextPage);
51
41
  $n.push(url.href);
52
42
  };
53
- const logout = () => {
54
- console.debug("LOGOUT");
55
- setTimeout(() => {
56
- gotoNextPage();
57
- setUserIdentity(undefined);
58
- setSubmitted(false);
59
- }, 3000);
60
- };
61
- const submit = async () => {
43
+ console.log({
44
+ hasContext,
45
+ userIdent,
46
+ data,
47
+ submitted,
48
+ verified,
49
+ verificationError,
50
+ success,
51
+ });
52
+ useEffect(() => {
53
+ const check = async () => {
54
+ var _a;
55
+ const response = await request({ oobCode });
56
+ if (response instanceof Error ||
57
+ !((_a = response === null || response === void 0 ? void 0 : response.verifyManagedIdentityEmail) === null || _a === void 0 ? void 0 : _a.success)) {
58
+ console.debug("set verification error");
59
+ setVerificationError({ message: true });
60
+ }
61
+ else {
62
+ console.debug("set success: true");
63
+ setSuccess(true);
64
+ }
65
+ console.debug("SUBMITTED", response);
66
+ setSubmitted(true);
67
+ };
68
+ if (!submitted)
69
+ check();
70
+ }, [submitted]);
71
+ useEffect(() => {
62
72
  var _a, _b;
63
- setSubmitted(true);
64
- const response = await request({ oobCode });
65
- if (response instanceof Error ||
66
- !((_a = response === null || response === void 0 ? void 0 : response.verifyManagedIdentityEmail) === null || _a === void 0 ? void 0 : _a.success)) {
67
- setVerificationError({ message: true });
68
- }
69
- else if ((_b = response === null || response === void 0 ? void 0 : response.verifyManagedIdentityEmail) === null || _b === void 0 ? void 0 : _b.success) {
70
- setSuccess(true);
71
- }
72
- if (email && email !== oobEmail) {
73
- console.debug("email mismatch", { response });
74
- logout();
73
+ if (!submitted)
75
74
  return;
75
+ if (!verificationError &&
76
+ // oob is valid + matching email OR logged in user is verified
77
+ ((success && ((_a = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _a === void 0 ? void 0 : _a.email) === oobEmail) || verified)) {
78
+ console.log("LOGGING IN", success, verified, verificationError);
79
+ setTimeout(gotoNextPage, 3000);
76
80
  }
77
- console.debug("SUBMITTED", response);
78
- };
79
- useEffect(() => {
80
- console.log({ verified, userIdent });
81
- if (verified) {
82
- setSuccess(true);
83
- setTimeout(() => {
84
- gotoNextPage();
81
+ else {
82
+ console.log("LOGGING OUT", success, verified, verificationError);
83
+ if ((_b = userIdent === null || userIdent === void 0 ? void 0 : userIdent.managedIdentity) === null || _b === void 0 ? void 0 : _b.email) {
85
84
  setUserIdentity(undefined);
86
- setSubmitted(false);
87
- }, 3000);
85
+ setTimeout(gotoNextPage, 3000);
86
+ }
88
87
  }
89
- else if (!data && !submitted && oobCode)
90
- submit();
91
- }, [verified, submitted, data, userIdent]);
92
- // console.log({ hasContext, userIdent, data, submitted, verified, errors });
93
- // useEffect(() => {
94
- // if (errors && !verified) setVerificationError(errors);
95
- // }, [errors, verified]);
88
+ }, [verified, verificationError, success, submitted, userIdent]);
89
+ useEffect(() => {
90
+ if (errors)
91
+ setVerificationError(errors);
92
+ }, [errors, setVerificationError]);
96
93
  // useEffect(() => {
97
- // if (!data && !submitted && oobCode) submit();
94
+ // if (!data && !submitted && oobCode) {
95
+ // submit();
96
+ // return;
97
+ // }
98
98
  // // verification successful but user in context is not verified
99
99
  // // or mismatch between logged in user and user associated with oobCode
100
100
  // if (submitted) {
@@ -7601,7 +7601,7 @@ const PortalResetPassword = /*#__PURE__*/Object.freeze({
7601
7601
  CodeValidating: CodeValidating
7602
7602
  });
7603
7603
 
7604
- const scenario$9 = "@author:derek\n@owner:ian\nFeature: Verify Email\n\n Background: A user is on the email verification page\n Given a user who has been redirected to the email verification page\n\n @motivating\n Scenario: Verifying your email takes you to the portal login page\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email is validated\n Then a button that says \"Continue\" appears\n When they click \"Continue\"\n Then they are redirected to login\n\n @motivating\n Scenario: Users are automatically redirected if they dont click \"Continue\"\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email is validated\n Then a button that says \"Continue\" appears\n When they wait 5 seconds\n Then they are redirected to login\n\n @motivating\n Scenario: Users are notified if verifying their email has failed\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email fails to be validated\n Then an banner is shown stating that an error occured\n\n @motivating\n Scenario Outline: Users cannot verify their email with an invalid or missing oob code\n Given a user has a <oobCode> as a url query parameter\n And the component <mayHave> \"failed-page\" with <value>\n Then they see an error message saying that their verification code is invalid/expired\n When they click \"Continue\"\n Then they are redirected to <redirectPath>\n Examples:\n | oobCode | mayHave | value | redirectPath |\n | invalid oob code | doesn't have | N/A | / |\n | non existant oob code | doesn't have | N/A | / |\n | invalid oob code | has | /login | /login |\n | non existant oob code | has | /login | /login |\n\n @motivating\n Scenario: Users are redirected to \"/\" by default\n Given the component does not have prop \"nextPage\"\n And the users url does not contain a \"nextPage\" query parameter\n And a user has verified their email\n When they click \"Continue\"\n Then they are redirected to \"/\"\n\n @motivating\n Scenario: Custom redirection can be configured\n Given the component has prop \"nextPage\" with value \"/activity\"\n And the users url does not contain a \"nextPage\" query parameter\n And a user has verified their email\n When they click \"Continue\"\n Then they are redirected to \"/activity\"\n\n @motivating\n Scenario Outline: Users are redirected to the value of the nextPage url parameter if it exists\n Given the component <mayHave> prop \"nextPage\" with <nextPageValue>\n And the users url contains a \"nextPage\" query paramater with <nextPageParamValue>\n And the user has verified their email\n When they click \"Continue\"\n Then they are redirected to <nextPageParamValue>\n Examples:\n | mayHave | nextPageValue | nextPageParamValue |\n | has | /dashboard | /activity |\n | does not have | N/A | /activity |\n\n @motivating\n Scenario Outline: Users are redirected to the value of the nextPage url parameter as if it were a relative path\n Given the component is loaded at <currentUrl>\n And the user has verified their email\n When they click \"Continue\"\n And they are redirected to <url>\n Examples:\n | currentUrl | url |\n | https://www.example.com?nextPage=./activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=/activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=www.google.com | https://www.example.com/www.google.com |\n | https://www.example.com?nextPage=//foo.com | https://www.example.com/ |\n | https://www.example.com?nextPage=https://malicious.example.com | https://www.example.com/ |\n | http://www.example.com/nest/page?oob=123&other&nextPage=activity#heading-1 | http://www.example.com/activity |\n | https://www.example.com?nextPage=activity?foo=bar | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar#hash | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar%23hash | https://www.example.com/activity?foo=bar#hash |\n | https://www.example.com:1337?nextPage=activity | https://www.example.com:1337/activity |\n | http://1.1.1.1:1111?nextPage=activity | http://1.1.1.1:1111/activity |\n\n @landmine\n Scenario Outline: Username and password are not persisted on redirects\n Given the component is loaded at <currentUrl>\n And the user has verified their email\n When they click \"Continue\"\n And they are redirected to <url>\n Examples:\n | currentUrl | url |\n | https://user:pass@www.example.com:444?nextPage=activity | https://www.example.com:444/activity |\n\n\n @minutia\n Scenario Outline: Users may be logged in or logged out depending on the verified status and logged in email\n Given an oobCode with email <oobCodeEmail> as a url query parameter\n And the user is logged in as <loggedInEmail>\n And the logged in user <isVerified>\n When the oobCode is submitted\n And the oobCode <isValid>\n Then the <submitState> screen is shown\n And after 3 seconds pass\n Then the user is redirected to <redirect>\n Examples:\n | oobCodeEmail | loggedInEmail | isVerified | isValid | submitState | redirect |\n | user1@example.com | N/A | false | is valid | success | /login |\n | user1@example.com | N/A | false | is not valid | error | /login |\n | user1@example.com | user1@example.com | false | is valid | success | /activity |\n | user1@example.com | user1@example.com | false | is not valid | error | N/A |\n | user1@example.com | user2@example.com | false | is valid | success | /login |\n | user1@example.com | user2@example.com | false | is not valid | error | /login |\n | user1@example.com | user1@example.com | true | is valid | success | /activity |\n | user1@example.com | user1@example.com | true | is not valid | success | /activity |\n | user1@example.com | user2@example.com | true | is not valid | error | /login |\n | N/A | N/A | false | is not valid | error | N/A |\n";
7604
+ const scenario$9 = "@author:derek\n@owner:ian\nFeature: Verify Email\n\n Background: A user is on the email verification page\n Given a user who has been redirected to the email verification page\n\n @motivating\n Scenario: Verifying your email takes you to the portal login page\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email is validated\n Then a button that says \"Continue\" appears\n When they click \"Continue\"\n Then they are redirected to login\n\n @motivating\n Scenario: Users are automatically redirected if they dont click \"Continue\"\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email is validated\n Then a button that says \"Continue\" appears\n When they wait 5 seconds\n Then they are redirected to login\n\n @motivating\n Scenario: Users are notified if verifying their email has failed\n Given a user has a valid oob code as a url query parameter\n When they click \"Verify Email\"\n Then the button enters a loading state\n When their email fails to be validated\n Then an banner is shown stating that an error occured\n\n @motivating\n Scenario Outline: Users cannot verify their email with an invalid or missing oob code\n Given a user has a <oobCode> as a url query parameter\n And the component <mayHave> \"failed-page\" with <value>\n Then they see an error message saying that their verification code is invalid/expired\n When they click \"Continue\"\n Then they are redirected to <redirectPath>\n Examples:\n | oobCode | mayHave | value | redirectPath |\n | invalid oob code | doesn't have | N/A | / |\n | non existant oob code | doesn't have | N/A | / |\n | invalid oob code | has | /login | /login |\n | non existant oob code | has | /login | /login |\n\n @motivating\n Scenario: Users are redirected to \"/\" by default\n Given the component does not have prop \"nextPage\"\n And the users url does not contain a \"nextPage\" query parameter\n And a user has verified their email\n When they click \"Continue\"\n Then they are redirected to \"/\"\n\n @motivating\n Scenario: Custom redirection can be configured\n Given the component has prop \"nextPage\" with value \"/activity\"\n And the users url does not contain a \"nextPage\" query parameter\n And a user has verified their email\n When they click \"Continue\"\n Then they are redirected to \"/activity\"\n\n @motivating\n Scenario Outline: Users are redirected to the value of the nextPage url parameter if it exists\n Given the component <mayHave> prop \"nextPage\" with <nextPageValue>\n And the users url contains a \"nextPage\" query paramater with <nextPageParamValue>\n And the user has verified their email\n When they click \"Continue\"\n Then they are redirected to <nextPageParamValue>\n Examples:\n | mayHave | nextPageValue | nextPageParamValue |\n | has | /dashboard | /activity |\n | does not have | N/A | /activity |\n\n @motivating\n Scenario Outline: Users are redirected to the value of the nextPage url parameter as if it were a relative path\n Given the component is loaded at <currentUrl>\n And the user has verified their email\n When they click \"Continue\"\n And they are redirected to <url>\n Examples:\n | currentUrl | url |\n | https://www.example.com?nextPage=./activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=/activity | https://www.example.com/activity |\n | https://www.example.com?nextPage=www.google.com | https://www.example.com/www.google.com |\n | https://www.example.com?nextPage=//foo.com | https://www.example.com/ |\n | https://www.example.com?nextPage=https://malicious.example.com | https://www.example.com/ |\n | http://www.example.com/nest/page?oob=123&other&nextPage=activity#heading-1 | http://www.example.com/activity |\n | https://www.example.com?nextPage=activity?foo=bar | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar#hash | https://www.example.com/activity?foo=bar |\n | https://www.example.com?nextPage=%2Factivity%3Ffoo%3Dbar%23hash | https://www.example.com/activity?foo=bar#hash |\n | https://www.example.com:1337?nextPage=activity | https://www.example.com:1337/activity |\n | http://1.1.1.1:1111?nextPage=activity | http://1.1.1.1:1111/activity |\n\n @landmine\n Scenario Outline: Username and password are not persisted on redirects\n Given the component is loaded at <currentUrl>\n And the user has verified their email\n When they click \"Continue\"\n And they are redirected to <url>\n Examples:\n | currentUrl | url |\n | https://user:pass@www.example.com:444?nextPage=activity | https://www.example.com:444/activity |\n\n\n @minutia\n Scenario Outline: Users may be logged in or logged out depending on the verified status and logged in email\n Given an oobCode with email <oobCodeEmail> as a url query parameter\n And the user is logged in as <loggedInEmail>\n And the logged in user <isVerified>\n When the oobCode is submitted\n And the oobCode <isValid>\n Then the <submitState> screen is shown\n And after 3 seconds pass\n Then the user is redirected to <redirect>\n Examples:\n | oobCodeEmail | loggedInEmail | isVerified | isValid | submitState | redirect |\n | user1@example.com | N/A | false | is valid | success | /login |\n | user1@example.com | N/A | false | is not valid | error | /login |\n | user1@example.com | user1@example.com | false | is valid | success | /activity |\n | user1@example.com | user1@example.com | false | is not valid | error | N/A |\n | user1@example.com | user2@example.com | false | is valid | success | /login |\n | user1@example.com | user2@example.com | false | is not valid | error | /login |\n | user1@example.com | user1@example.com | true | is valid | success | /activity |\n | user1@example.com | user1@example.com | true | is not valid | success | /activity |\n | user1@example.com | user2@example.com | true | is not valid | error | /login |\n | N/A | N/A | false | is not valid | error | N/A |\n";
7605
7605
 
7606
7606
  const PortalVerifyEmail_stories = {
7607
7607
  title: "Components/Microsite Verify Email",
@@ -1 +1 @@
1
- var __awaiter=this&&this.__awaiter||function(e,t,i,r){function n(e){return e instanceof i?e:new i((function(t){t(e)}))}return new(i||(i=Promise))((function(i,a){function o(e){try{l(r.next(e))}catch(e){a(e)}}function s(e){try{l(r["throw"](e))}catch(e){a(e)}}function l(e){e.done?i(e.value):n(e.value).then(o,s)}l((r=r.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var i={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,n,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return l([e,t])}}function l(o){if(r)throw new TypeError("Generator is already executing.");while(i)try{if(r=1,n&&(a=o[0]&2?n["return"]:o[0]?n["throw"]||((a=n["return"])&&a.call(n),0):n.next)&&!(a=a.call(n,o[1])).done)return a;if(n=0,a)o=[o[0]&2,a.value];switch(o[0]){case 0:case 1:a=o;break;case 4:i.label++;return{value:o[1],done:false};case 5:i.label++;n=o[1];o=[0];continue;case 7:o=i.ops.pop();i.trys.pop();continue;default:if(!(a=i.trys,a=a.length>0&&a[a.length-1])&&(o[0]===6||o[0]===2)){i=0;continue}if(o[0]===3&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(o[0]===6&&i.label<a[1]){i.label=a[1];a=o;break}if(a&&i.label<a[2]){i.label=a[2];i.ops.push(o);break}if(a[2])i.ops.pop();i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e];n=0}finally{r=a=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:true}}};import{r as registerInstance,h as h$1}from"./index-17b4da69.js";import{k as useState,f as useEffect,n as h}from"./stencil-hooks.module-8032b139.js";import{j as an,$ as $n,b as setUserIdentity,i as isDemo}from"./index.module-ba0ed7a8.js";import{c as cjs}from"./cjs-bdfb4486.js";import"./mixins-f60a614c.js";import"./JSS-67b5cff8.js";import{s as sanitizeUrlPath,g as getProps}from"./utils-334c1e34.js";import"./sqm-text-span-view-8d140661.js";import{P as PortalVerifyEmailView}from"./sqm-portal-verify-email-view-279b4e58.js";var SUBMITTED_CONTEXT="sq:verify-submitted";function setSubmitted(e){window[SUBMITTED_CONTEXT]=e}function usePortalVerifyEmail(e){var t=this;var i=e.nextPage,r=e.failedPage,n=e.verifySuccessText,a=e.verifyEmailText,o=e.verifyInvalidText,s=e.networkErrorMessage,l=e.continueText;var u,d,c,f,v,m,y,h,g;var p=window[SUBMITTED_CONTEXT];var b=useState(null),T=b[0],x=b[1];var E=useState(false),w=E[0],P=E[1];var S=an(),I=S[0],_=S[1],k=_.loading,j=_.data,V=_.errors;var U=new URLSearchParams($n.location.search);var C=U.get("oobCode");var M=U.get("email");var D=U.get("nextPage");var $=j===undefined&&V===undefined&&!!C;var N=localStorage.getItem("sq:user-identity");var O=X(N);var q=(u=O===null||O===void 0?void 0:O.managedIdentity)===null||u===void 0?void 0:u.email;var B=!!(((d=O===null||O===void 0?void 0:O.managedIdentity)===null||d===void 0?void 0:d.emailVerified)||(j===null||j===void 0?void 0:j.verifyManagedIdentityEmail.success));function X(e){try{return JSON.parse(e)}catch(e){return undefined}}var z=function(){return $n.push({pathname:r,search:U.toString()&&"?"+U.toString()})};var G=function(){U.delete("nextPage");var e=sanitizeUrlPath(D||i);$n.push(e.href)};var J=function(){console.debug("LOGOUT");setTimeout((function(){G();setUserIdentity(undefined);setSubmitted(false)}),3e3)};var L=function(){return __awaiter(t,void 0,void 0,(function(){var e,t,i;return __generator(this,(function(r){switch(r.label){case 0:setSubmitted(true);return[4,I({oobCode:C})];case 1:i=r.sent();if(i instanceof Error||!((e=i===null||i===void 0?void 0:i.verifyManagedIdentityEmail)===null||e===void 0?void 0:e.success)){x({message:true})}else if((t=i===null||i===void 0?void 0:i.verifyManagedIdentityEmail)===null||t===void 0?void 0:t.success){P(true)}if(q&&q!==M){console.debug("email mismatch",{response:i});J();return[2]}console.debug("SUBMITTED",i);return[2]}}))}))};useEffect((function(){console.log({verified:B,userIdent:O});if(B){P(true);setTimeout((function(){G();setUserIdentity(undefined);setSubmitted(false)}),3e3)}else if(!j&&!p&&C)L()}),[B,p,j,O]);return{states:{loading:k||$,success:w,error:((m=(v=(f=(c=T===null||T===void 0?void 0:T.response)===null||c===void 0?void 0:c.errors)===null||f===void 0?void 0:f[0])===null||v===void 0?void 0:v.extensions)===null||m===void 0?void 0:m.message)||((g=(h=(y=T===null||T===void 0?void 0:T.response)===null||y===void 0?void 0:y.errors)===null||h===void 0?void 0:h[0])===null||g===void 0?void 0:g.message)||(T===null||T===void 0?void 0:T.message)&&s,verified:B},data:{oobCode:C},callbacks:{failed:z,gotoNextPage:G},content:{verifySuccessText:n,verifyEmailText:a,verifyInvalidText:o,continueText:l}}}var PortalVerifyEmail=function(){function e(e){registerInstance(this,e);this.ignored=true;this.nextPage="/";this.failedPage="/";this.verifyEmailText="Verify your email";this.verifySuccessText="Your email has been verified and you are being redirected. If you are not redirected, please click Continue.";this.verifyInvalidText="The email verification code is invalid or has expired, please try again.";this.continueText="Continue";this.networkErrorMessage="An error occurred while verifying your email. Please refresh the page and try again.";h(this)}e.prototype.disconnectedCallback=function(){};e.prototype.render=function(){var e=isDemo()?usePortalVerifyEmailDemo(getProps(this)):usePortalVerifyEmail(getProps(this)),t=e.states,i=e.data,r=e.callbacks,n=e.content;return h$1(PortalVerifyEmailView,{states:t,data:i,callbacks:r,content:n})};return e}();function usePortalVerifyEmailDemo(e){return cjs({states:{error:"",loading:false,verified:true},data:{oobCode:"code"},callbacks:{failed:function(){console.log("failed")},gotoNextPage:function(){}},content:{verifySuccessText:e.verifySuccessText,verifyEmailText:e.verifyEmailText,verifyInvalidText:e.verifyInvalidText,continueText:e.continueText}},e.demoData||{},{arrayMerge:function(e,t){return t}})}export{PortalVerifyEmail as sqm_portal_verify_email};
1
+ var __awaiter=this&&this.__awaiter||function(e,t,i,r){function n(e){return e instanceof i?e:new i((function(t){t(e)}))}return new(i||(i=Promise))((function(i,a){function o(e){try{l(r.next(e))}catch(e){a(e)}}function s(e){try{l(r["throw"](e))}catch(e){a(e)}}function l(e){e.done?i(e.value):n(e.value).then(o,s)}l((r=r.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var i={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,n,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return l([e,t])}}function l(o){if(r)throw new TypeError("Generator is already executing.");while(i)try{if(r=1,n&&(a=o[0]&2?n["return"]:o[0]?n["throw"]||((a=n["return"])&&a.call(n),0):n.next)&&!(a=a.call(n,o[1])).done)return a;if(n=0,a)o=[o[0]&2,a.value];switch(o[0]){case 0:case 1:a=o;break;case 4:i.label++;return{value:o[1],done:false};case 5:i.label++;n=o[1];o=[0];continue;case 7:o=i.ops.pop();i.trys.pop();continue;default:if(!(a=i.trys,a=a.length>0&&a[a.length-1])&&(o[0]===6||o[0]===2)){i=0;continue}if(o[0]===3&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(o[0]===6&&i.label<a[1]){i.label=a[1];a=o;break}if(a&&i.label<a[2]){i.label=a[2];i.ops.push(o);break}if(a[2])i.ops.pop();i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e];n=0}finally{r=a=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:true}}};import{r as registerInstance,h as h$1}from"./index-17b4da69.js";import{k as useState,f as useEffect,n as h}from"./stencil-hooks.module-8032b139.js";import{Q,j as an,$ as $n,b as setUserIdentity,i as isDemo}from"./index.module-ba0ed7a8.js";import{c as cjs}from"./cjs-bdfb4486.js";import"./mixins-f60a614c.js";import"./JSS-67b5cff8.js";import{s as sanitizeUrlPath,g as getProps}from"./utils-334c1e34.js";import"./sqm-text-span-view-8d140661.js";import{P as PortalVerifyEmailView}from"./sqm-portal-verify-email-view-279b4e58.js";var SUBMITTED_CONTEXT="sq:verify-submitted";function setSubmitted(e){window[SUBMITTED_CONTEXT]=e}function usePortalVerifyEmail(e){var t=this;var i=e.nextPage,r=e.failedPage,n=e.verifySuccessText,a=e.verifyEmailText,o=e.verifyInvalidText,s=e.networkErrorMessage,l=e.continueText;var u,c,d,f,v,m,y,g;var h=window[SUBMITTED_CONTEXT];var p=Q();var b=useState(null),x=b[0],T=b[1];var E=useState(false),w=E[0],P=E[1];var I=an(),S=I[0],_=I[1],k=_.loading,j=_.data,V=_.errors;var C=new URLSearchParams($n.location.search);var U=C.get("oobCode");var D=C.get("email");var M=C.get("nextPage");var N=j===undefined&&V===undefined&&!!U;var G=localStorage.getItem("sq:user-identity");var $=!!(((u=p===null||p===void 0?void 0:p.managedIdentity)===null||u===void 0?void 0:u.emailVerified)||(j===null||j===void 0?void 0:j.verifyManagedIdentityEmail.success));var O=function(){return $n.push({pathname:r,search:C.toString()&&"?"+C.toString()})};var q=function(){C.delete("nextPage");var e=sanitizeUrlPath(M||i);$n.push(e.href)};console.log({hasContext:G,userIdent:p,data:j,submitted:h,verified:$,verificationError:x,success:w});useEffect((function(){var e=function(){return __awaiter(t,void 0,void 0,(function(){var e,t;return __generator(this,(function(i){switch(i.label){case 0:return[4,S({oobCode:U})];case 1:t=i.sent();if(t instanceof Error||!((e=t===null||t===void 0?void 0:t.verifyManagedIdentityEmail)===null||e===void 0?void 0:e.success)){console.debug("set verification error");T({message:true})}else{console.debug("set success: true");P(true)}console.debug("SUBMITTED",t);setSubmitted(true);return[2]}}))}))};if(!h)e()}),[h]);useEffect((function(){var e,t;if(!h)return;if(!x&&(w&&((e=p===null||p===void 0?void 0:p.managedIdentity)===null||e===void 0?void 0:e.email)===D||$)){console.log("LOGGING IN",w,$,x);setTimeout(q,3e3)}else{console.log("LOGGING OUT",w,$,x);if((t=p===null||p===void 0?void 0:p.managedIdentity)===null||t===void 0?void 0:t.email){setUserIdentity(undefined);setTimeout(q,3e3)}}}),[$,x,w,h,p]);useEffect((function(){if(V)T(V)}),[V,T]);return{states:{loading:k||N,success:w,error:((v=(f=(d=(c=x===null||x===void 0?void 0:x.response)===null||c===void 0?void 0:c.errors)===null||d===void 0?void 0:d[0])===null||f===void 0?void 0:f.extensions)===null||v===void 0?void 0:v.message)||((g=(y=(m=x===null||x===void 0?void 0:x.response)===null||m===void 0?void 0:m.errors)===null||y===void 0?void 0:y[0])===null||g===void 0?void 0:g.message)||(x===null||x===void 0?void 0:x.message)&&s,verified:$},data:{oobCode:U},callbacks:{failed:O,gotoNextPage:q},content:{verifySuccessText:n,verifyEmailText:a,verifyInvalidText:o,continueText:l}}}var PortalVerifyEmail=function(){function e(e){registerInstance(this,e);this.ignored=true;this.nextPage="/";this.failedPage="/";this.verifyEmailText="Verify your email";this.verifySuccessText="Your email has been verified and you are being redirected. If you are not redirected, please click Continue.";this.verifyInvalidText="The email verification code is invalid or has expired, please try again.";this.continueText="Continue";this.networkErrorMessage="An error occurred while verifying your email. Please refresh the page and try again.";h(this)}e.prototype.disconnectedCallback=function(){};e.prototype.render=function(){var e=isDemo()?usePortalVerifyEmailDemo(getProps(this)):usePortalVerifyEmail(getProps(this)),t=e.states,i=e.data,r=e.callbacks,n=e.content;return h$1(PortalVerifyEmailView,{states:t,data:i,callbacks:r,content:n})};return e}();function usePortalVerifyEmailDemo(e){return cjs({states:{error:"",loading:false,verified:true},data:{oobCode:"code"},callbacks:{failed:function(){console.log("failed")},gotoNextPage:function(){}},content:{verifySuccessText:e.verifySuccessText,verifyEmailText:e.verifyEmailText,verifyInvalidText:e.verifyInvalidText,continueText:e.continueText}},e.demoData||{},{arrayMerge:function(e,t){return t}})}export{PortalVerifyEmail as sqm_portal_verify_email};