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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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