Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions .changeset/blue-grapes-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
---

Move usage of internal useCoreX hooks to useX hooks
5 changes: 3 additions & 2 deletions packages/clerk-js/src/ui.retheme/common/EmailLinkVerify.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { EmailLinkErrorCode, isEmailLinkError } from '@clerk/shared/error';
import { useClerk } from '@clerk/shared/react';
import React from 'react';

import type { VerificationStatus } from '../../utils';
import { completeSignUpFlow } from '../../utils';
import { useCoreClerk, useCoreSignUp } from '../contexts';
import { useCoreSignUp } from '../contexts';
import type { LocalizationKey } from '../localization';
import { useRouter } from '../router';
import { sleep } from '../utils';
Expand All @@ -19,7 +20,7 @@ export type EmailLinkVerifyProps = {

export const EmailLinkVerify = (props: EmailLinkVerifyProps) => {
const { redirectUrl, redirectUrlComplete, verifyEmailPath, verifyPhonePath } = props;
const { handleEmailLinkVerification } = useCoreClerk();
const { handleEmailLinkVerification } = useClerk();
const { navigate } = useRouter();
const signUp = useCoreSignUp();
const [verificationStatus, setVerificationStatus] = React.useState<VerificationStatus>('loading');
Expand Down
6 changes: 3 additions & 3 deletions packages/clerk-js/src/ui.retheme/common/Gate.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useSession } from '@clerk/shared/react';
import type { CheckAuthorization } from '@clerk/types';
import type { ComponentType, PropsWithChildren, ReactNode } from 'react';
import React, { useEffect } from 'react';

import { useCoreSession } from '../contexts';
import { useRouter } from '../router';

type GateParams = Parameters<CheckAuthorization>[0];
Expand All @@ -14,10 +14,10 @@ type GateProps = PropsWithChildren<
>;

export const useGate = (params: GateParams) => {
const { experimental__checkAuthorization } = useCoreSession();
const { session } = useSession();

return {
isAuthorizedUser: experimental__checkAuthorization(params),
isAuthorizedUser: session?.experimental__checkAuthorization(params),
};
};

Expand Down
4 changes: 2 additions & 2 deletions packages/clerk-js/src/ui.retheme/common/SSOCallback.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useClerk } from '@clerk/shared/react';
import type { HandleOAuthCallbackParams, HandleSamlCallbackParams } from '@clerk/types';
import React from 'react';

import { useCoreClerk } from '../contexts';
import { Flow } from '../customizables';
import { Card, CardAlert, LoadingCardContainer, useCardState, withCardStateProvider } from '../elements';
import { useRouter } from '../router';
Expand All @@ -16,7 +16,7 @@ export const SSOCallback = withCardStateProvider<HandleOAuthCallbackParams | Han
});

export const SSOCallbackCard = (props: HandleOAuthCallbackParams | HandleSamlCallbackParams) => {
const { handleRedirectCallback } = useCoreClerk();
const { handleRedirectCallback } = useClerk();
const { navigate } = useRouter();
const card = useCardState();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useClerk } from '@clerk/shared/react';
import type { ComponentType } from 'react';
import React from 'react';

import { warnings } from '../../core/warnings';
import type { ComponentGuard } from '../../utils';
import { noOrganizationExists, noUserExists, sessionExistsAndSingleSessionModeEnabled } from '../../utils';
import { useCoreClerk, useEnvironment, useOptions } from '../contexts';
import { useEnvironment, useOptions } from '../contexts';
import { useRouter } from '../router';
import type { AvailableComponentProps } from '../types';

Expand All @@ -18,7 +19,7 @@ function withRedirectToHome<P extends AvailableComponentProps>(

const HOC = (props: P) => {
const { navigate } = useRouter();
const clerk = useCoreClerk();
const clerk = useClerk();
const environment = useEnvironment();
const options = useOptions();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useOrganization, useOrganizationList } from '@clerk/shared/react';
import type { OrganizationResource } from '@clerk/types';
import React from 'react';

import { useWizard, Wizard } from '../../common';
import { useCoreOrganization, useCoreOrganizationList } from '../../contexts';
import { Icon } from '../../customizables';
import { ContentPage, Form, FormButtonContainer, IconButton, SuccessPage, useCardState } from '../../elements';
import { QuestionMark, Upload } from '../../icons';
Expand Down Expand Up @@ -30,8 +30,8 @@ export const CreateOrganizationForm = (props: CreateOrganizationFormProps) => {
const wizard = useWizard({ onNextStep: () => card.setError(undefined) });

const lastCreatedOrganizationRef = React.useRef<OrganizationResource | null>(null);
const { createOrganization, isLoaded, setActive } = useCoreOrganizationList();
const { organization } = useCoreOrganization();
const { createOrganization, isLoaded, setActive } = useOrganizationList();
const { organization } = useOrganization();
const [file, setFile] = React.useState<File | null>();

const nameField = useFormControl('name', '', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useCoreClerk, useCreateOrganizationContext } from '../../contexts';
import { useClerk } from '@clerk/shared/react';

import { useCreateOrganizationContext } from '../../contexts';
import { localizationKeys } from '../../customizables';
import { withCardStateProvider } from '../../elements';
import { CreateOrganizationForm } from './CreateOrganizationForm';

export const CreateOrganizationPage = withCardStateProvider(() => {
const title = localizationKeys('createOrganization.title');
const { closeCreateOrganization } = useCoreClerk();
const { closeCreateOrganization } = useClerk();

const { mode, navigateAfterCreateOrganization, skipInvitationScreen } = useCreateOrganizationContext();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useClerk, useSession } from '@clerk/shared/react';
import type { PointerEventHandler } from 'react';
import React, { useEffect, useRef } from 'react';

import { getFullName, getIdentifier } from '../../../utils/user';
import { useCoreClerk, useCoreSession, withCoreUserGuard } from '../../contexts';
import { withCoreUserGuard } from '../../contexts';
import type { LocalizationKey } from '../../customizables';
import {
Col,
Expand Down Expand Up @@ -57,8 +58,8 @@ const EyeCircle = ({ width, height, ...props }: EyeCircleProps) => {
type FabContentProps = { title: LocalizationKey; signOutText: LocalizationKey };

const FabContent = ({ title, signOutText }: FabContentProps) => {
const session = useCoreSession();
const { signOut } = useCoreClerk();
const { session } = useSession();
const { signOut } = useClerk();

return (
<Col
Expand Down Expand Up @@ -88,15 +89,16 @@ const FabContent = ({ title, signOutText }: FabContentProps) => {
})}
localizationKey={signOutText}
onClick={async () => {
await signOut({ sessionId: session.id });
// clerk-js has been loaded at this point so we can safely access session
await signOut({ sessionId: session!.id });
}}
/>
</Col>
);
};

const _ImpersonationFab = () => {
const session = useCoreSession();
const { session } = useSession();
const { t } = useLocalizations();
const { parsedInternalTheme } = useAppearance();
const containerRef = useRef<HTMLDivElement>(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useOrganizationList } from '@clerk/shared/react';
import { useState } from 'react';

import { useCoreOrganizationList, useEnvironment, useOrganizationListContext } from '../../contexts';
import { useEnvironment, useOrganizationListContext } from '../../contexts';
import { Box, Button, Col, descriptors, Flex, localizationKeys, Spinner } from '../../customizables';
import { Card, CardAlert, Divider, Header, useCardState, withCardStateProvider } from '../../elements';
import { useInView } from '../../hooks';
Expand All @@ -11,8 +12,8 @@ import { MembershipPreview, PersonalAccountPreview } from './UserMembershipList'
import { SuggestionPreview } from './UserSuggestionList';
import { organizationListParams } from './utils';

const useCoreOrganizationListInView = () => {
const { userMemberships, userInvitations, userSuggestions } = useCoreOrganizationList(organizationListParams);
const useOrganizationListInView = () => {
const { userMemberships, userInvitations, userSuggestions } = useOrganizationList(organizationListParams);

const { ref } = useInView({
threshold: 0,
Expand Down Expand Up @@ -40,7 +41,7 @@ const useCoreOrganizationListInView = () => {

export const OrganizationListPage = withCardStateProvider(() => {
const card = useCardState();
const { userMemberships, userSuggestions, userInvitations } = useCoreOrganizationListInView();
const { userMemberships, userSuggestions, userInvitations } = useOrganizationListInView();
const isLoading = userMemberships?.isLoading || userInvitations?.isLoading || userSuggestions?.isLoading;
const hasAnyData = !!(userMemberships?.count || userInvitations?.count || userSuggestions?.count);

Expand Down Expand Up @@ -118,7 +119,7 @@ const OrganizationListFlows = ({ showListInitially }: { showListInitially: boole
const OrganizationListPageList = (props: { onCreateOrganizationClick: () => void }) => {
const environment = useEnvironment();

const { ref, userMemberships, userSuggestions, userInvitations } = useCoreOrganizationListInView();
const { ref, userMemberships, userSuggestions, userInvitations } = useOrganizationListInView();
const { hidePersonal } = useOrganizationListContext();

const isLoading = userMemberships?.isLoading || userInvitations?.isLoading || userSuggestions?.isLoading;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useClerk, useOrganizationList } from '@clerk/shared/react';
import type { OrganizationResource, UserOrganizationInvitationResource } from '@clerk/types';
import { useState } from 'react';

import { useCoreClerk, useCoreOrganizationList } from '../../contexts';
import { localizationKeys } from '../../customizables';
import { useCardState, withCardStateProvider } from '../../elements';
import { handleError } from '../../utils';
Expand All @@ -24,9 +24,9 @@ export const AcceptRejectInvitationButtons = (props: { onAccept: () => void }) =

export const InvitationPreview = withCardStateProvider((props: UserOrganizationInvitationResource) => {
const card = useCardState();
const { getOrganization } = useCoreClerk();
const { getOrganization } = useClerk();
const [acceptedOrganization, setAcceptedOrganization] = useState<OrganizationResource | null>(null);
const { userInvitations } = useCoreOrganizationList({
const { userInvitations } = useOrganizationList({
userInvitations: organizationListParams.userInvitations,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { useOrganizationList, useUser } from '@clerk/shared/react';
import type { OrganizationResource } from '@clerk/types';

import { useCoreOrganizationList, useCoreUser, useOrganizationListContext } from '../../contexts';
import { useOrganizationListContext } from '../../contexts';
import { OrganizationPreview, PersonalWorkspacePreview, useCardState, withCardStateProvider } from '../../elements';
import { localizationKeys } from '../../localization';
import { OrganizationListPreviewButton, sharedMainIdentifierSx } from './shared';

export const MembershipPreview = withCardStateProvider((props: { organization: OrganizationResource }) => {
const card = useCardState();
const { navigateAfterSelectOrganization } = useOrganizationListContext();
const { isLoaded, setActive } = useCoreOrganizationList();
const { isLoaded, setActive } = useOrganizationList();

if (!isLoaded) {
return null;
Expand All @@ -35,8 +36,12 @@ export const MembershipPreview = withCardStateProvider((props: { organization: O
export const PersonalAccountPreview = withCardStateProvider(() => {
const card = useCardState();
const { hidePersonal, navigateAfterSelectPersonal } = useOrganizationListContext();
const { isLoaded, setActive } = useCoreOrganizationList();
const user = useCoreUser();
const { isLoaded, setActive } = useOrganizationList();
const { user } = useUser();

if (!user) {
return null;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ is this a fix to avoid rendering PersonalAccountPreview when user is not available or the useCoreUser() has different behaviour from the useUser() ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OrganizationList is wrapped in withCoreUserGuard so we are safe. It doesn't really matter if we do user?.something or return null.

Here we did that because it was helping with the deconstruction.


const { username, primaryEmailAddress, primaryPhoneNumber, ...userWithoutIdentifiers } = user;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useOrganizationList } from '@clerk/shared/react';
import type { OrganizationSuggestionResource } from '@clerk/types';

import { useCoreOrganizationList } from '../../contexts';
import { localizationKeys, Text } from '../../customizables';
import { useCardState, withCardStateProvider } from '../../elements';
import { handleError } from '../../utils';
Expand All @@ -10,7 +10,7 @@ import { organizationListParams } from './utils';

export const AcceptRejectInvitationButtons = (props: OrganizationSuggestionResource) => {
const card = useCardState();
const { userSuggestions } = useCoreOrganizationList({
const { userSuggestions } = useOrganizationList({
userSuggestions: organizationListParams.userSuggestions,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { useCoreOrganizationList } from '../../contexts';
import type { useOrganizationList } from '@clerk/shared/react';

export const organizationListParams = {
userMemberships: {
Expand All @@ -11,4 +11,4 @@ export const organizationListParams = {
infinite: true,
status: ['pending', 'accepted'],
},
} satisfies Parameters<typeof useCoreOrganizationList>[0];
} satisfies Parameters<typeof useOrganizationList>[0];
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useOrganization, useUser } from '@clerk/shared/react';

import { useWizard, Wizard } from '../../common';
import { useCoreOrganization, useCoreUser, useOrganizationProfileContext } from '../../contexts';
import { useOrganizationProfileContext } from '../../contexts';
import type { LocalizationKey } from '../../customizables';
import { localizationKeys, Text } from '../../customizables';
import {
Expand All @@ -17,10 +19,10 @@ import { OrganizationProfileBreadcrumbs } from './OrganizationProfileNavbar';
export const LeaveOrganizationPage = () => {
const card = useCardState();
const { navigateAfterLeaveOrganization } = useOrganizationProfileContext();
const { organization } = useCoreOrganization();
const user = useCoreUser();
const { organization } = useOrganization();
const { user } = useUser();

if (!organization) {
if (!organization || !user) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

return null;
}

Expand Down Expand Up @@ -50,7 +52,7 @@ export const LeaveOrganizationPage = () => {
export const DeleteOrganizationPage = () => {
const card = useCardState();
const { navigateAfterLeaveOrganization } = useOrganizationProfileContext();
const { organization } = useCoreOrganization();
const { organization } = useOrganization();

if (!organization) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useOrganization, useUser } from '@clerk/shared/react';
import type { OrganizationMembershipResource } from '@clerk/types';

import { Gate } from '../../common/Gate';
import { useCoreOrganization, useCoreUser } from '../../contexts';
import { Badge, localizationKeys, Td, Text } from '../../customizables';
import { ThreeDotsMenu, useCardState, UserPreview } from '../../elements';
import { useFetchRoles, useLocalizeCustomRoles } from '../../hooks/useFetchRoles';
Expand All @@ -17,7 +17,7 @@ const membershipsParams = {

export const ActiveMembersList = () => {
const card = useCardState();
const { organization, memberships } = useCoreOrganization(membershipsParams);
const { organization, memberships } = useOrganization(membershipsParams);

const { options, isLoading: loadingRoles } = useFetchRoles();

Expand Down Expand Up @@ -76,9 +76,9 @@ const MemberRow = (props: {
const { membership, onRemove, onRoleChange, options } = props;
const { localizeCustomRole } = useLocalizeCustomRoles();
const card = useCardState();
const user = useCoreUser();
const { user } = useUser();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Don't we need if (!user) return null; guard here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OrganizationProfile is wrapped in withCoreUserGuard so we are safe.


const isCurrentUser = user.id === membership.publicUserData.userId;
const isCurrentUser = user?.id === membership.publicUserData.userId;
const unlocalizedRoleLabel = options?.find(a => a.value === membership.role)?.label;

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useOrganization } from '@clerk/shared/react';
import React from 'react';

import { useCoreOrganization, useEnvironment } from '../../contexts';
import { useEnvironment } from '../../contexts';
import { localizationKeys } from '../../customizables';
import { ContentPage, Form, FormButtons, useCardState, withCardStateProvider } from '../../elements';
import { useRouter } from '../../router';
Expand All @@ -13,7 +14,7 @@ export const AddDomainPage = withCardStateProvider(() => {
const subtitle = localizationKeys('organizationProfile.createDomainPage.subtitle');
const breadcrumbTitle = localizationKeys('organizationProfile.profilePage.domainSection.title');
const card = useCardState();
const { organization } = useCoreOrganization();
const { organization } = useOrganization();
const { navigate } = useRouter();

const nameField = useFormControl('name', '', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useOrganization } from '@clerk/shared/react';
import type {
GetDomainsParams,
OrganizationDomainResource,
Expand All @@ -8,7 +9,6 @@ import React, { useMemo } from 'react';

import { stripOrigin, toURL, trimLeadingSlash } from '../../../utils';
import { useGate, withGate } from '../../common';
import { useCoreOrganization } from '../../contexts';
import type { LocalizationKey } from '../../customizables';
import { Box, Col, descriptors, localizationKeys, Spinner } from '../../customizables';
import { ArrowBlockButton, BlockWithTrailingComponent, ThreeDotsMenu } from '../../elements';
Expand Down Expand Up @@ -81,7 +81,7 @@ const DomainListDotMenu = ({
export const DomainList = withGate(
(props: DomainListProps) => {
const { verificationStatus, enrollmentMode, redirectSubPath, fallback, ...rest } = props;
const { organization, domains } = useCoreOrganization({
const { organization, domains } = useOrganization({
domains: {
infinite: true,
...rest,
Expand Down
Loading