Skip to content

Commit

Permalink
Prod release (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
cermakjiri authored Dec 5, 2024
2 parents 452b5aa + 11d5969 commit 2f48406
Show file tree
Hide file tree
Showing 30 changed files with 444 additions and 207 deletions.
2 changes: 0 additions & 2 deletions examples/webauthn-default/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const nextConfig: NextConfig = {
},

transpilePackages: ['@workspace/common'] satisfies Dependency[],

redirects: async () => [],
};

// Make sure adding Sentry options is the last code to run before exporting, to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { signInWithCustomToken } from 'firebase/auth';

import { fetcher } from '@workspace/common/client/api/fetcher';
import { parseUnknownError } from '@workspace/common/client/errors';
import { track } from '@workspace/common/client/firebase/analytics';
import { auth } from '@workspace/common/client/firebase/config';
import type { FormProps } from '@workspace/common/client/form/components';
import { logger } from '@workspace/common/logger';
Expand All @@ -17,6 +18,7 @@ export function useLoginWithPasskey(): FormProps<LoginFormSchema, LoginFormValue
const { redirect } = useExampleRouter();

return async function loginWithPasskey({ email: username }, { setError }) {
track('example_default_login_request');
try {
const {
data: { publicKeyOptions },
Expand Down Expand Up @@ -49,6 +51,8 @@ export function useLoginWithPasskey(): FormProps<LoginFormSchema, LoginFormValue
// NOTE: The Authorization header with ID token is set in request inceptor in AuthProvider.tsx component.

redirect('/passkeys');

track('example_default_login_success');
} catch (error) {
const parsedError = await parseUnknownError(error);

Expand All @@ -57,6 +61,8 @@ export function useLoginWithPasskey(): FormProps<LoginFormSchema, LoginFormValue
});

logger.error(error);

track('example_default_login_failure');
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useMutation } from '@tanstack/react-query';
import { queryClient } from '@workspace/common/client/api/components';
import { fetcher } from '@workspace/common/client/api/fetcher';
import { parseUnknownError } from '@workspace/common/client/errors';
import { track } from '@workspace/common/client/firebase/analytics';
import { useSnack } from '@workspace/common/client/snackbar/hooks';
import { logger } from '@workspace/common/logger';

Expand All @@ -14,6 +15,8 @@ export function useAddPasskey() {

return useMutation({
mutationFn: async () => {
track('example_default_add_passkey_request');

const {
data: { publicKeyOptions },
} = await fetcher<StartLinkingResponseData>({
Expand Down Expand Up @@ -47,9 +50,11 @@ export function useAddPasskey() {
logger.error(parsedError);

snack('error', parsedError.message);
track('example_default_add_passkey_failure');
},
onSuccess() {
snack('success', 'Passkey has been successfully added.');
track('example_default_add_passkey_success');
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { queryClient } from '@workspace/common/client/api/components';
import { fetcher } from '@workspace/common/client/api/fetcher';
import { parseUnknownError } from '@workspace/common/client/errors';
import { useAuthUser } from '@workspace/common/client/example/components';
import { track } from '@workspace/common/client/firebase/analytics';
import type { PostRemovalDialogProps } from '@workspace/common/client/passkeys/components';
import { useSnack } from '@workspace/common/client/snackbar/hooks';
import { logger } from '@workspace/common/logger';
Expand All @@ -21,6 +22,8 @@ export function useRemovePasskey(openDialog: (data: PostRemovalDialogProps['data

return useMutation({
mutationFn: async (passkeyId: string) => {
track('example_default_remove_passkey_request');

try {
const {
data: { publicKeyOptions },
Expand Down Expand Up @@ -59,12 +62,16 @@ export function useRemovePasskey(openDialog: (data: PostRemovalDialogProps['data
await queryClient.invalidateQueries({
queryKey: ['passkeys'],
});

track('example_default_remove_passkey_success');
} catch (error) {
const parsedError = await parseUnknownError(error);

snack('error', parsedError.message);

logger.error(error);

track('example_default_remove_passkey_failure');
}
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ export const RegisterWithPasskeyPage = () => {
<Box sx={{ textAlign: 'center', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
<Words variant='body2'>Already have an account?</Words>

<Button variant='text' onClick={() => redirect('/login')}>
<Button
variant='text'
onClick={() => {
redirect('/login');
}}
>
Login
</Button>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { signInWithCustomToken } from 'firebase/auth';

import { fetcher } from '@workspace/common/client/api/fetcher';
import { parseUnknownError } from '@workspace/common/client/errors';
import { track } from '@workspace/common/client/firebase/analytics';
import { auth } from '@workspace/common/client/firebase/config';
import type { FormProps } from '@workspace/common/client/form/components';
import { logger } from '@workspace/common/logger';
Expand All @@ -20,6 +21,8 @@ export function useRegisterWithPasskey(): FormProps<RegisterFormSchema, Register
const { redirect } = useExampleRouter();

return async function registerPasskey({ email: username }, { setError }) {
track('example_default_register_request');

try {
const {
data: { publicKeyOptions },
Expand Down Expand Up @@ -52,6 +55,8 @@ export function useRegisterWithPasskey(): FormProps<RegisterFormSchema, Register
// NOTE: The Authorization header with ID token is set in request inceptor in AuthProvider.tsx component.

redirect('/passkeys');

track('example_default_register_success');
} catch (error) {
const parsedError = await parseUnknownError(error);

Expand All @@ -60,6 +65,8 @@ export function useRegisterWithPasskey(): FormProps<RegisterFormSchema, Register
});

logger.error(error);

track('example_default_register_failure');
}
};
}
2 changes: 0 additions & 2 deletions examples/webauthn-upgrade/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const nextConfig: NextConfig = {
},

transpilePackages: ['@workspace/common'] satisfies Dependency[],

redirects: async () => [],
};

// Make sure adding Sentry options is the last code to run before exporting, to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { parseAsString, parseAsStringLiteral, useQueryStates } from 'nuqs';

import { QueryLoader } from '@workspace/common/client/api/components';
import { env } from '@workspace/common/client/env';
import { track } from '@workspace/common/client/firebase/analytics';
import { auth } from '@workspace/common/client/firebase/config';

import { useExampleRouter } from '../router';
Expand Down Expand Up @@ -41,6 +42,8 @@ export function EmailVerificationCode({ children }: EmailVerificationCodeProps)

redirect('/login-with-password');

track('example_upgrade_register_email_verified');

await push(continueUrl);

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { signInWithCustomToken } from 'firebase/auth';

import { fetcher } from '@workspace/common/client/api/fetcher';
import { parseUnknownError } from '@workspace/common/client/errors';
import { track } from '@workspace/common/client/firebase/analytics';
import { auth } from '@workspace/common/client/firebase/config';
import type { FormProps } from '@workspace/common/client/form/components';
import { logger } from '@workspace/common/logger';
Expand All @@ -23,6 +24,7 @@ export function useLoginWithEmailAndPassword({
const { redirect } = useExampleRouter();

return async function loginWithEmailAndPassword({ email, password }, { setError }) {
track('example_upgrade_login_request');
try {
const { data: loginResult } = await fetcher<LoginResponseData>({
method: 'POST',
Expand Down Expand Up @@ -61,6 +63,8 @@ export function useLoginWithEmailAndPassword({
onSuccess();

redirect('/passkeys');

track('example_upgrade_login_success');
} catch (error) {
const parsedError = await parseUnknownError(error);

Expand All @@ -69,6 +73,8 @@ export function useLoginWithEmailAndPassword({
});

logger.error(error);

track('example_upgrade_login_failure');
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { signInWithCustomToken } from 'firebase/auth';

import { fetcher } from '@workspace/common/client/api/fetcher';
import { parseUnknownError } from '@workspace/common/client/errors';
import { track } from '@workspace/common/client/firebase/analytics';
import { auth } from '@workspace/common/client/firebase/config';
import { logger } from '@workspace/common/logger';

Expand All @@ -17,6 +18,7 @@ export function useLoginWithPasskey() {

return useMutation<void, Awaited<ReturnType<typeof parseUnknownError>>>({
mutationFn: async () => {
track('example_upgrade_login_passkey_request');
try {
const {
data: { publicKeyOptions },
Expand Down Expand Up @@ -47,7 +49,10 @@ export function useLoginWithPasskey() {

// NOTE: The Authorization header with ID token is set in request inceptor in AuthProvider.tsx component.
redirect('/passkeys');

track('example_upgrade_login_passkey_success');
} catch (error) {
track('example_upgrade_login_passkey_failure');
throw await parseUnknownError(error);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useMutation } from '@tanstack/react-query';
import { queryClient } from '@workspace/common/client/api/components';
import { fetcher } from '@workspace/common/client/api/fetcher';
import { parseUnknownError } from '@workspace/common/client/errors';
import { track } from '@workspace/common/client/firebase/analytics';
import { useSnack } from '@workspace/common/client/snackbar/hooks';
import { logger } from '@workspace/common/logger';

Expand All @@ -17,6 +18,7 @@ export function useAddPasskey() {

return useMutation({
mutationFn: async () => {
track('example_upgrade_add_passkey_request');
const {
data: { publicKeyOptions },
} = await fetcher<StartLinkingResponseData>({
Expand Down Expand Up @@ -54,9 +56,11 @@ export function useAddPasskey() {
logger.error(parsedError);

snack('error', parsedError.message);
track('example_upgrade_add_passkey_failure');
},
onSuccess() {
snack('success', 'Passkey has been successfully added.');
track('example_upgrade_add_passkey_success');
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { queryClient } from '@workspace/common/client/api/components';
import { fetcher } from '@workspace/common/client/api/fetcher';
import { parseUnknownError } from '@workspace/common/client/errors';
import { useAuthUser } from '@workspace/common/client/example/components';
import { track } from '@workspace/common/client/firebase/analytics';
import type { PostRemovalDialogProps } from '@workspace/common/client/passkeys/components';
import { useSnack } from '@workspace/common/client/snackbar/hooks';
import { logger } from '@workspace/common/logger';
Expand All @@ -23,6 +24,7 @@ export function useRemovePasskey(openDialog: (data: PostRemovalDialogProps['data

return useMutation({
mutationFn: async (passkeyId: string) => {
track('example_upgrade_remove_passkey_request');
try {
const {
data: { publicKeyOptions },
Expand Down Expand Up @@ -65,12 +67,14 @@ export function useRemovePasskey(openDialog: (data: PostRemovalDialogProps['data
await queryClient.invalidateQueries({
queryKey: ['passkeys'],
});
track('example_upgrade_remove_passkey_success');
} catch (error) {
const parsedError = await parseUnknownError(error);

snack('error', parsedError.message);

logger.error(error);
track('example_upgrade_remove_passkey_failure');
}
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ export const RegisterWithEmailAndPasswordPage = () => {
<Box sx={{ textAlign: 'center', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
<Words variant='body2'>Already have an account?</Words>

<Button variant='text' onClick={() => redirect('/login')}>
<Button
variant='text'
onClick={() => {
redirect('/login');
}}
>
Login
</Button>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { sendEmailVerification, signInWithCustomToken, signOut, type User } from

import { fetcher } from '@workspace/common/client/api/fetcher';
import { parseUnknownError } from '@workspace/common/client/errors';
import { track } from '@workspace/common/client/firebase/analytics';
import { auth } from '@workspace/common/client/firebase/config';
import type { FormProps } from '@workspace/common/client/form/components';
import { useSnack } from '@workspace/common/client/snackbar/hooks';
Expand Down Expand Up @@ -29,6 +30,8 @@ export function useRegisterWithEmailAndPassword(): FormProps<RegisterFormSchema,
const snack = useSnack();

return async function registerPasskey({ email, password }, { setError, reset }) {
track('example_upgrade_register_request');

try {
const {
data: { customToken },
Expand Down Expand Up @@ -61,6 +64,8 @@ export function useRegisterWithEmailAndPassword(): FormProps<RegisterFormSchema,
)}
</>,
);

track('example_upgrade_register_success');
} catch (error) {
const parsedError = await parseUnknownError(error);

Expand All @@ -69,6 +74,8 @@ export function useRegisterWithEmailAndPassword(): FormProps<RegisterFormSchema,
});

logger.error(error);

track('example_upgrade_register_failure');
}
};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@tooling/eslint": "workspace:*",
"@tooling/prettier": "workspace:*",
"@tooling/typescript": "workspace:*",
"dotenv": "16.4.5",
"dotenv": "16.4.7",
"husky": "9.1.7",
"turbo": "2.3.3"
},
Expand Down
12 changes: 6 additions & 6 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"@mui/lab": "6.0.0-beta.14",
"@mui/material": "6.1.8",
"@mui/system": "6.1.8",
"@sentry/nextjs": "8.41.0",
"@simplewebauthn/browser": "11.0.0",
"@simplewebauthn/server": "11.0.0",
"@sentry/nextjs": "8.42.0",
"@simplewebauthn/browser": "12.0.0",
"@simplewebauthn/server": "12.0.0",
"@t3-oss/env-nextjs": "0.11.1",
"@tanstack/react-query": "5.61.5",
"@tanstack/react-query-devtools": "5.61.5",
"@tanstack/react-query": "5.62.2",
"@tanstack/react-query-devtools": "5.62.2",
"@workspace/logger": "workspace:*",
"cookie": "1.0.2",
"core-js": "3.39.0",
Expand All @@ -51,7 +51,7 @@
"@tooling/madge": "workspace:*",
"@tooling/prettier": "workspace:*",
"@tooling/typescript": "workspace:*",
"@types/react": "18.3.12",
"@types/react": "18.3.13",
"@types/react-dom": "18.3.1",
"tsc-alias": "1.8.10"
}
Expand Down
Loading

0 comments on commit 2f48406

Please sign in to comment.