Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passkey list for react package #89

Merged
merged 11 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/react-sdk/src/contexts/CorbadoContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ export interface CorbadoContextProps {
completeSignUpWithEmailOTP: (code: string) => Promise<Result<void, CompleteSignupWithEmailOTPError>>;
appendPasskey: () => Promise<Result<void, AppendPasskeyError>>;
getUserAuthMethods: (email: string) => Promise<UserAuthMethods>;
passkeyList: () => Promise<Result<PassKeyList, PasskeyListError>>;
passkeyDelete: (id: string) => Promise<Result<void, PasskeyDeleteError>>;
getPasskeys: () => Promise<Result<PassKeyList, PasskeyListError>>;
deletePasskey: (id: string) => Promise<Result<void, PasskeyDeleteError>>;
getProjectConfig: () => Promise<ProjectConfig>;
}

const missingImplementation = (): never => {
throw new Error('Please make sure that your components are wrapped inside <CorbadoProvider/>');
};

export const initialContext = {
export const initialContext: CorbadoContextProps = {
shortSession: undefined,
user: undefined,
globalError: undefined,
Expand All @@ -53,10 +53,9 @@ export const initialContext = {
logout: missingImplementation,
initSignUpWithEmailOTP: missingImplementation,
completeSignUpWithEmailOTP: missingImplementation,
initAutocompletedLoginWithPasskey: missingImplementation,
appendPasskey: missingImplementation,
passkeyList: missingImplementation,
passkeyDelete: missingImplementation,
getPasskeys: missingImplementation,
deletePasskey: missingImplementation,
getUserAuthMethods: missingImplementation,
getProjectConfig: missingImplementation,
};
Expand Down
12 changes: 6 additions & 6 deletions packages/react-sdk/src/contexts/CorbadoProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ export const CorbadoProvider: FC<AppProviderParams> = ({ children, ...corbadoPar
return corbadoApp.authService.appendPasskey();
}, [corbadoApp]);

const passkeyList = useCallback(() => {
const getPasskeys = useCallback(() => {
return corbadoApp.authService.passkeyList();
}, [corbadoApp]);

const passkeyDelete = useCallback(
const deletePasskey = useCallback(
(id: string) => {
return corbadoApp.authService.passkeyDelete(id);
},
Expand Down Expand Up @@ -137,8 +137,8 @@ export const CorbadoProvider: FC<AppProviderParams> = ({ children, ...corbadoPar
initSignUpWithEmailOTP,
completeSignUpWithEmailOTP,
appendPasskey,
passkeyList,
passkeyDelete,
getPasskeys,
deletePasskey,
getUserAuthMethods,
getProjectConfig,
};
Expand All @@ -156,8 +156,8 @@ export const CorbadoProvider: FC<AppProviderParams> = ({ children, ...corbadoPar
initSignUpWithEmailOTP,
completeSignUpWithEmailOTP,
appendPasskey,
passkeyList,
passkeyDelete,
getPasskeys,
deletePasskey,
getUserAuthMethods,
getProjectConfig,
]);
Expand Down
17 changes: 10 additions & 7 deletions packages/react/src/components/passkeyList/PasskeyDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { aaguidMappings, getParsedUA } from '@corbado/shared-ui';
import type { PassKeyItem } from '@corbado/types';
import type { FC } from 'react';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Trans, useTranslation } from 'react-i18next';

export interface PasskeyDetailsProps {
passkey: PassKeyItem;
Expand All @@ -24,12 +24,15 @@ const PasskeyDetails: FC<PasskeyDetailsProps> = ({ passkey }) => {
{passkey.id}
</div>
<div>
{t('field_created_text1')}
{passkey.created}
{t('field_created_text2')}
{userAgent?.browser.name}
{t('field_created_text3')}
{userAgent?.os.name}
<Trans
i18nKey='field_created'
t={t}
values={{
date: passkey.created,
browser: userAgent.browser.name,
os: userAgent.os.name,
}}
/>
</div>
<div>
{t('field_lastUsed')}
Expand Down
12 changes: 0 additions & 12 deletions packages/react/src/contexts/CorbadoUIContext.ts

This file was deleted.

28 changes: 0 additions & 28 deletions packages/react/src/contexts/CorbadoUIProvider.tsx

This file was deleted.

25 changes: 20 additions & 5 deletions packages/react/src/hocs/CorbadoProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import '../i18n';

import { CorbadoProvider as CorbadoSDKProvider } from '@corbado/react-sdk';
import { handleTheming } from '@corbado/shared-ui';
import type { CorbadoAppParams, CorbadoUIConfig } from '@corbado/types';
import type { FC, PropsWithChildren } from 'react';
import React from 'react';
import React, { useEffect } from 'react';

import CorbadoUIProvider from '../contexts/CorbadoUIProvider';
import { handleDynamicLocaleSetup } from '../i18n';

export type CorbadoProviderProps = PropsWithChildren<CorbadoUIConfig & CorbadoAppParams>;

const CorbadoProvider: FC<CorbadoProviderProps> = ({ children, ...config }) => {
const { defaultLanguage, autoDetectLanguage, customTranslations, darkMode, theme } = config;

useEffect(() => {
handleDynamicLocaleSetup(autoDetectLanguage, defaultLanguage, customTranslations);
const themesCleanup = handleTheming(darkMode ?? 'auto', theme);

return themesCleanup;
}, []);

return (
<CorbadoUIProvider {...config}>
<CorbadoSDKProvider {...config}>{children}</CorbadoSDKProvider>
</CorbadoUIProvider>
<CorbadoSDKProvider
projectId={config.projectId}
apiTimeout={config.apiTimeout}
>
{children}
</CorbadoSDKProvider>
);
};
export default CorbadoProvider;
23 changes: 0 additions & 23 deletions packages/react/src/hocs/CorbadoScreen.tsx

This file was deleted.

16 changes: 0 additions & 16 deletions packages/react/src/hooks/useCorbadoUIConfig.ts

This file was deleted.

5 changes: 2 additions & 3 deletions packages/react/src/screens/CorbadoAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import React from 'react';
import { AuthFlow } from '../components/wrappers/AuthFlow';
import FlowHandlerProvider from '../contexts/FlowHandlerProvider';
import UserDataProvider from '../contexts/UserDataProvider';
import CorbadoScreen from '../hocs/CorbadoScreen';

const CorbadoAuth: FC<CorbadoAuthConfig> = ({ onLoggedIn }) => {
return (
<CorbadoScreen>
<div>
<div className='cb-container'>
<UserDataProvider>
<FlowHandlerProvider
Expand All @@ -21,7 +20,7 @@ const CorbadoAuth: FC<CorbadoAuthConfig> = ({ onLoggedIn }) => {
</FlowHandlerProvider>
</UserDataProvider>
</div>
</CorbadoScreen>
</div>
);
};

Expand Down
11 changes: 5 additions & 6 deletions packages/react/src/screens/PasskeyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import { Button, Spinner } from '../components';
import PasskeyAgentIcon from '../components/passkeyList/PasskeyAgentIcon';
import PasskeyDelete from '../components/passkeyList/PasskeyDelete';
import PasskeyDetails from '../components/passkeyList/PasskeyDetails';
import CorbadoScreen from '../hocs/CorbadoScreen';

const PasskeyList: FC = () => {
const { passkeyList, appendPasskey, passkeyDelete, shortSession } = useCorbado();
const { getPasskeys, appendPasskey, deletePasskey, shortSession } = useCorbado();
const { t } = useTranslation('translation', { keyPrefix: 'passkeysList' });
const [passkeys, setPasskeys] = useState<PassKeyList | undefined>();

Expand All @@ -24,7 +23,7 @@ const PasskeyList: FC = () => {
}, []);

const fetchPasskeys = async () => {
const result = await passkeyList();
const result = await getPasskeys();

if (result.err) {
throw new Error(result.val.name);
Expand All @@ -39,7 +38,7 @@ const PasskeyList: FC = () => {
};

const handleDeletePasskey = async (id: string) => {
await passkeyDelete(id);
await deletePasskey(id);
await fetchPasskeys();
};

Expand All @@ -48,7 +47,7 @@ const PasskeyList: FC = () => {
}

return (
<CorbadoScreen>
<div>
{passkeys ? (
passkeys.passkeys.map(passkey => (
<div
Expand All @@ -74,7 +73,7 @@ const PasskeyList: FC = () => {
>
{t('button_createPasskey')}
</Button>
</CorbadoScreen>
</div>
);
};

Expand Down
4 changes: 1 addition & 3 deletions packages/shared-ui/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@
"button_createPasskey": "Create a Passkey",
"badge_synced": "Synced",
"field_credentialId": "Credential ID: ",
"field_created_text1": "Created: ",
"field_created_text2": " with ",
"field_created_text3": " on ",
"field_created": "Created: {{date}} with {{browser}} on {{os}}",
Aby-JS marked this conversation as resolved.
Show resolved Hide resolved
"field_lastUsed": "Last used: ",
"field_status": "Status: ",
"deleteDialog_header": "Delete Passkey",
Expand Down
Loading