Skip to content

Commit

Permalink
chore(expo): Use error thrower and move useOAuth hook
Browse files Browse the repository at this point in the history
  • Loading branch information
octoper committed May 30, 2024
1 parent 28b5c35 commit c6bf6bb
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
8 changes: 5 additions & 3 deletions packages/expo/src/components/uiComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ import {
} from '@clerk/clerk-react';
import { Platform } from 'react-native';

import { errorThrower } from '../utils/errors';

const ErrorComponent = (componentName: string) => {
throw new Error(`<${componentName}/> is not supported on this platform`);
throw errorThrower.throw(`The ${componentName} component is not supported in the Expo environment.`);
};

function WrapComponent<T extends { displayName: string }>(component: T) {
const commonentName = component.displayName.replace('withClerk(', '').replace(')', '');

// @ts-expect-error - This is a hack to make the function signature match the original
// @ts-expect-error - This is just to make the function signature match the original
return Platform.select<T>({
// @ts-expect-error - This is a hack to make the function signature match the original
// @ts-expect-error - This is just to make the function signature match the original
native: () => () => ErrorComponent(commonentName),
default: () => component,
})();
Expand Down
1 change: 0 additions & 1 deletion packages/expo/src/hooks/useOAuth.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/expo/src/hooks/useOAuth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useOAuth';
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export function useOAuth(useOAuthParams: UseOAuthFlowParams) {
// @ts-ignore
externalVerificationRedirectURL.toString(),
oauthRedirectUrl,
{
showInRecents: true,
},
);

// @ts-expect-error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { OAuthStrategy } from '@clerk/types';
import { Platform } from 'react-native';

import { errorThrower } from '../../utils/errors';

export type UseOAuthFlowParams = {
strategy: OAuthStrategy;
redirectUrl?: string;
unsafeMetadata?: SignUpUnsafeMetadata;
};
export function useOAuth(_useOAuthParams: UseOAuthFlowParams) {
if (Platform.OS === 'web') {
throw new Error('OAuth flow is not supported in web');
throw errorThrower.throw('useOAuth hook is not supported in Web');
}
}
2 changes: 1 addition & 1 deletion packages/expo/src/utils/errors.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { buildErrorThrower } from '@clerk/shared/error';

export const errorThrower = buildErrorThrower({ packageName: PACKAGE_NAME });
export const errorThrower = buildErrorThrower({ packageName: PACKAGE_NAME, customMessages: [] });

0 comments on commit c6bf6bb

Please sign in to comment.