Skip to content

Commit

Permalink
fixed build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Aby-JS committed Dec 21, 2023
1 parent 573ce84 commit 8ad6c8a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
25 changes: 8 additions & 17 deletions packages/react/src/contexts/FlowHandlerProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
import { useCorbado } from '@corbado/react-sdk';
import type {
FlowHandlerConfig,
FlowHandlerEventOptions,
FlowHandlerEvents,
FlowNames,
ScreenNames,
UserState,
} from '@corbado/shared-ui';
import { CommonScreens, FlowHandler, FlowType, LoginFlowNames, SignUpFlowNames } from '@corbado/shared-ui';
import type { FlowHandlerEventOptions, FlowHandlerEvents, FlowNames, ScreenNames, UserState } from '@corbado/shared-ui';
import { CommonScreens, FlowHandler, SignUpFlowNames } from '@corbado/shared-ui';
import i18n from 'i18next';
import type { FC, PropsWithChildren } from 'react';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';

import type { FlowHandlerContextProps } from './FlowHandlerContext';
import FlowHandlerContext from './FlowHandlerContext';

type Props = FlowHandlerConfig;
type Props = {
onLoggedIn: () => void;
};

export const FlowHandlerProvider: FC<PropsWithChildren<Props>> = ({ children, ...props }) => {
const { corbadoApp, getProjectConfig, user } = useCorbado();
const [flowHandler, setFlowHandler] = useState<FlowHandler>();
const [currentScreen, setCurrentScreen] = useState<ScreenNames>(CommonScreens.Start);
const [currentUserState, setCurrentUserState] = useState<UserState>({});
const [currentFlow, setCurrentFlow] = useState<FlowNames>(
props.initialFlowType === FlowType.Login
? LoginFlowNames.PasskeyLoginWithEmailOTPFallback
: SignUpFlowNames.PasskeySignupWithEmailOTPFallback,
);
const [currentFlow, setCurrentFlow] = useState<FlowNames>(SignUpFlowNames.PasskeySignupWithEmailOTPFallback);
const [initialized, setInitialized] = useState(false);
const onScreenChangeCbId = useRef<number>(0);
const onFlowChangeCbId = useRef<number>(0);
Expand All @@ -44,15 +35,15 @@ export const FlowHandlerProvider: FC<PropsWithChildren<Props>> = ({ children, ..
return;
}

const flowHandler = new FlowHandler(projectConfig.val, props, i18n);
const flowHandler = new FlowHandler(projectConfig.val, props.onLoggedIn);

onScreenChangeCbId.current = flowHandler.onScreenChange((value: ScreenNames) => setCurrentScreen(value));
onFlowChangeCbId.current = flowHandler.onFlowChange((value: FlowNames) => setCurrentFlow(value));
onUserStateChangeCbId.current = flowHandler.onUserStateChange((value: UserState) => {
setCurrentUserState(value);
});

void flowHandler.init(corbadoApp);
void flowHandler.init(corbadoApp, i18n);

setFlowHandler(flowHandler);
setInitialized(true);
Expand Down
6 changes: 1 addition & 5 deletions packages/react/src/screens/CorbadoAuth.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FlowType } from '@corbado/shared-ui';
import type { CorbadoAuthConfig } from '@corbado/types';
import type { FC } from 'react';
import React from 'react';
Expand All @@ -9,10 +8,7 @@ import FlowHandlerProvider from '../contexts/FlowHandlerProvider';
const CorbadoAuth: FC<CorbadoAuthConfig> = ({ onLoggedIn, isDevMode = false, customerSupportEmail = '' }) => {
return (
<div className='cb-container'>
<FlowHandlerProvider
onLoggedIn={onLoggedIn}
initialFlowType={FlowType.SignUp}
>
<FlowHandlerProvider onLoggedIn={onLoggedIn}>
<AuthFlow
isDevMode={isDevMode}
customerSupportEmail={customerSupportEmail}
Expand Down
4 changes: 2 additions & 2 deletions packages/shared-ui/src/flowHandler/flows/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { LoginFlowNames, SignUpFlowNames } from '../constants';
import type { Flows } from '../types';
import { PasskeyLoginWithEmailOTPFallbackFlow } from './login/passkeyLoginWithOtpFlow';
import { PasskeySignupWithEmailOTPFallbackFlow } from './singup/passkeySignupWithOtpFlow';
import { PasskeySignupWithEmailOTPFallbackFlow } from './signup/passkeySignupWithOtpFlow';

export const flows: Flows = {
[SignUpFlowNames.PasskeySignupWithEmailOTPFallback]: PasskeySignupWithEmailOTPFallbackFlow,
[LoginFlowNames.PasskeyLoginWithEmailOTPFallback]: PasskeyLoginWithEmailOTPFallbackFlow,
};
export * from './singup/passkeySignupWithOtpFlow';
export * from './signup/passkeySignupWithOtpFlow';
export * from './login/passkeyLoginWithOtpFlow';
2 changes: 2 additions & 0 deletions packages/types/src/ui/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface CorbadoUIConfig {
*
* @interface CorbadoAuthConfig
* @property {() => void} onLoggedIn - A callback function that is called when the user is logged in.
* @property {boolean} [isDevMode] - A boolean indicating whether the app is running in development mode. Defaults to false if not provided.
* @property {string} [customerSupportEmail] - The email address to be used for customer support. Defaults to '
*/
export interface CorbadoAuthConfig {
onLoggedIn: () => void;
Expand Down

0 comments on commit 8ad6c8a

Please sign in to comment.