Skip to content

Commit 4adeb61

Browse files
authored
Add low events (#600)
1 parent e185904 commit 4adeb61

8 files changed

Lines changed: 895 additions & 14 deletions

File tree

examples/nextjs/tsconfig.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "es5",
4-
"lib": [
5-
"dom",
6-
"dom.iterable",
7-
"esnext"
8-
],
4+
"lib": ["dom", "dom.iterable", "esnext"],
95
"allowJs": true,
106
"skipLibCheck": true,
117
"strict": true,
@@ -23,9 +19,7 @@
2319
}
2420
],
2521
"paths": {
26-
"@/*": [
27-
"./*"
28-
]
22+
"@/*": ["./*"]
2923
}
3024
},
3125
"include": [
@@ -37,7 +31,5 @@
3731
"scripts/seed.js",
3832
".next/dev/types/**/*.ts"
3933
],
40-
"exclude": [
41-
"node_modules"
42-
]
34+
"exclude": ["node_modules"]
4335
}

packages/connect-react/src/components/login/LoginInitScreen.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const LoginInitScreen: FC<Props> = ({ showFallback = false }) => {
128128
return navigateToScreen(LoginScreenType.PasskeyReLogin);
129129
} else if (flags.hasSupportForConditionalUI()) {
130130
log.debug('starting conditional UI');
131-
void startConditionalUI(res.val.conditionalUIChallenge);
131+
void startConditionalUI(res.val.conditionalUIChallenge, flags);
132132
}
133133

134134
statefulLoader.current.finish();
@@ -143,11 +143,15 @@ const LoginInitScreen: FC<Props> = ({ showFallback = false }) => {
143143
};
144144
}, [getConnectService]);
145145

146-
const startConditionalUI = async (challenge: string | null) => {
146+
const startConditionalUI = async (challenge: string | null, resolvedFlags: Flags) => {
147147
if (!challenge) {
148148
return;
149149
}
150150

151+
if (resolvedFlags.hasSupportForEventLow()) {
152+
getConnectService().enqueueLowEvent({ eventType: 'cui-ready', timestamp: Date.now() });
153+
}
154+
151155
let cuiStarted = false;
152156
const res = await getConnectService().conditionalUILogin(
153157
ac => config.onConditionalLoginStart?.(ac),
@@ -187,6 +191,7 @@ const LoginInitScreen: FC<Props> = ({ showFallback = false }) => {
187191
}
188192

189193
try {
194+
await getConnectService().flushLowEvents();
190195
await config.onComplete(
191196
connectLoginFinishToComplete(res.val),
192197
getConnectService().encodeClientState(),
@@ -204,6 +209,7 @@ const LoginInitScreen: FC<Props> = ({ showFallback = false }) => {
204209

205210
setIdentifierBasedLoading(true);
206211
setCurrentIdentifier(identifier);
212+
await getConnectService().flushLowEvents();
207213
config.onLoginStart?.();
208214

209215
const resStart = await getConnectService().loginStart(identifier, PasskeyLoginSource.TextField, loadedMs);
@@ -242,6 +248,7 @@ const LoginInitScreen: FC<Props> = ({ showFallback = false }) => {
242248
}
243249

244250
try {
251+
await getConnectService().flushLowEvents();
245252
await config.onComplete(
246253
connectLoginFinishToComplete(res.val),
247254
getConnectService().encodeClientState(),
@@ -328,6 +335,7 @@ const LoginInitScreen: FC<Props> = ({ showFallback = false }) => {
328335
// This is needed to enable multiple login instances on the same page however only one should have the autocomplete
329336
// Else the conditionalUI won't work
330337
const autoComplete = useMemo(() => (flags?.hasSupportForConditionalUI() ? 'username webauthn' : ''), [flags]);
338+
const enableEventLow = useMemo(() => flags?.hasSupportForEventLow() ?? false, [flags]);
331339

332340
switch (loginInitState) {
333341
case LoginInitState.SilentLoading:
@@ -340,6 +348,7 @@ const LoginInitScreen: FC<Props> = ({ showFallback = false }) => {
340348
isLoading={cuiBasedLoading || identifierBasedLoading}
341349
error={error}
342350
autoComplete={autoComplete}
351+
enableEventLow={enableEventLow}
343352
handleSubmit={() => void handleSubmit()}
344353
handleIdentifierUpdate={(v: string) => setIdentifier(v)}
345354
/>

packages/connect-react/src/components/login/base/LoginInitLoaded.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import React from 'react';
1+
import React, { useRef } from 'react';
22

3+
import useLoginInputEventLow from '../../../hooks/useLoginInputEventLow';
4+
import useShared from '../../../hooks/useShared';
35
import InputField from '../../shared/InputField';
46
import { LinkButton } from '../../shared/LinkButton';
57
import { Notification } from '../../shared/Notification';
@@ -9,6 +11,7 @@ interface Props {
911
isLoading: boolean;
1012
error: string | undefined;
1113
autoComplete: string;
14+
enableEventLow?: boolean;
1215
onSignupClick?: () => void;
1316
handleSubmit: () => void;
1417
handleIdentifierUpdate: (v: string) => void;
@@ -19,9 +22,19 @@ const LoginInitLoaded = ({
1922
error,
2023
onSignupClick,
2124
autoComplete,
25+
enableEventLow = false,
2226
handleSubmit,
2327
handleIdentifierUpdate,
2428
}: Props) => {
29+
const inputRef = useRef<HTMLInputElement>(null);
30+
const { getConnectService } = useShared();
31+
32+
useLoginInputEventLow({
33+
inputRef,
34+
connectService: getConnectService(),
35+
enabled: enableEventLow,
36+
});
37+
2538
return (
2639
<>
2740
{error ? (
@@ -37,6 +50,7 @@ const LoginInitLoaded = ({
3750
autoComplete={autoComplete}
3851
autoFocus={true}
3952
placeholder=''
53+
ref={inputRef}
4054
onChange={e => handleIdentifierUpdate(e.target.value)}
4155
/>
4256
<PrimaryButton

0 commit comments

Comments
 (0)