diff --git a/.changeset/hip-bees-warn.md b/.changeset/hip-bees-warn.md new file mode 100644 index 0000000000..34d209edf0 --- /dev/null +++ b/.changeset/hip-bees-warn.md @@ -0,0 +1,14 @@ +--- +'@clerk/clerk-js': patch +'@clerk/shared': patch +'@clerk/clerk-react': patch +--- + +Warn about *MagicLink* deprecations: + +- `MagicLinkError` +- `isMagicLinkError` +- `MagicLinkErrorCode` +- `handleMagicLinkVerification` +- `createMagicLinkFlow` +- `useMagicLink` diff --git a/packages/clerk-js/src/core/clerk.ts b/packages/clerk-js/src/core/clerk.ts index 93262f0a48..094fc19b74 100644 --- a/packages/clerk-js/src/core/clerk.ts +++ b/packages/clerk-js/src/core/clerk.ts @@ -820,6 +820,8 @@ export default class Clerk implements ClerkInterface { params: HandleMagicLinkVerificationParams, customNavigate?: (to: string) => Promise, ): Promise => { + deprecated('handleMagicLinkVerification', 'Use `handleEmailLinkVerification` instead.'); + if (!this.client) { return; } diff --git a/packages/clerk-js/src/core/resources/EmailAddress.ts b/packages/clerk-js/src/core/resources/EmailAddress.ts index 4995a054d8..340fb620ee 100644 --- a/packages/clerk-js/src/core/resources/EmailAddress.ts +++ b/packages/clerk-js/src/core/resources/EmailAddress.ts @@ -1,4 +1,4 @@ -import { Poller } from '@clerk/shared'; +import { deprecated, Poller } from '@clerk/shared'; import type { AttemptEmailAddressVerificationParams, CreateEmailLinkFlowReturn, @@ -52,6 +52,8 @@ export class EmailAddress extends BaseResource implements EmailAddressResource { * @deprecated Use `createEmailLinkFlow` instead. */ createMagicLinkFlow = (): CreateMagicLinkFlowReturn => { + deprecated('createMagicLinkFlow', 'Use `createEmailLinkFlow` instead.'); + const { run, stop } = Poller(); const startMagicLinkFlow = async ({ redirectUrl }: StartMagicLinkFlowParams): Promise => { diff --git a/packages/clerk-js/src/core/resources/SignIn.ts b/packages/clerk-js/src/core/resources/SignIn.ts index d3586d3df4..1cf73b7841 100644 --- a/packages/clerk-js/src/core/resources/SignIn.ts +++ b/packages/clerk-js/src/core/resources/SignIn.ts @@ -1,4 +1,4 @@ -import { deepSnakeToCamel, Poller } from '@clerk/shared'; +import { deepSnakeToCamel, deprecated, Poller } from '@clerk/shared'; import type { AttemptFirstFactorParams, AttemptSecondFactorParams, @@ -125,6 +125,8 @@ export class SignIn extends BaseResource implements SignInResource { * @deprecated Use `createEmailLinkFlow` instead. */ createMagicLinkFlow = (): CreateMagicLinkFlowReturn => { + deprecated('createMagicLinkFlow', 'Use `createEmailLinkFlow` instead.'); + const { run, stop } = Poller(); const startMagicLinkFlow = async ({ diff --git a/packages/clerk-js/src/core/resources/SignUp.ts b/packages/clerk-js/src/core/resources/SignUp.ts index 97fd1a643f..d5129c4763 100644 --- a/packages/clerk-js/src/core/resources/SignUp.ts +++ b/packages/clerk-js/src/core/resources/SignUp.ts @@ -119,6 +119,8 @@ export class SignUp extends BaseResource implements SignUpResource { * @deprecated Use `createEmailLinkFlow` instead. */ createMagicLinkFlow = (): CreateMagicLinkFlowReturn => { + deprecated('createMagicLinkFlow', 'Use `createEmailLinkFlow` instead.'); + const { run, stop } = Poller(); const startMagicLinkFlow = async ({ redirectUrl }: StartMagicLinkFlowParams): Promise => { diff --git a/packages/react/src/hooks/useMagicLink.ts b/packages/react/src/hooks/useMagicLink.ts index 7203de0aff..673f62c1d3 100644 --- a/packages/react/src/hooks/useMagicLink.ts +++ b/packages/react/src/hooks/useMagicLink.ts @@ -1,3 +1,4 @@ +import { deprecated } from '@clerk/shared'; import type { CreateMagicLinkFlowReturn, EmailAddressResource, @@ -28,6 +29,8 @@ function useMagicLink(resource: EmailAddressResource): UseMagicLinkEmailAddressR function useMagicLink( resource: MagicLinkable, ): UseMagicLinkSignInReturn | UseMagicLinkSignUpReturn | UseMagicLinkEmailAddressReturn { + deprecated('useMagicLink', 'Use `useEmailLink` instead.'); + const { startMagicLinkFlow, cancelMagicLinkFlow } = React.useMemo(() => resource.createMagicLinkFlow(), [resource]); React.useEffect(() => { diff --git a/packages/react/src/isomorphicClerk.ts b/packages/react/src/isomorphicClerk.ts index b68ad6411b..f3c9035e98 100644 --- a/packages/react/src/isomorphicClerk.ts +++ b/packages/react/src/isomorphicClerk.ts @@ -672,6 +672,7 @@ export default class IsomorphicClerk { * @deprecated Use `handleEmailLinkVerification` instead. */ handleMagicLinkVerification = async (params: HandleMagicLinkVerificationParams): Promise => { + deprecated('handleMagicLinkVerification', 'Use `handleEmailLinkVerification` instead.'); const callback = () => this.clerkjs?.handleMagicLinkVerification(params); if (this.clerkjs && this.#loaded) { return callback() as Promise; diff --git a/packages/shared/src/errors/Error.ts b/packages/shared/src/errors/Error.ts index 256ebbd1a6..066dffa627 100644 --- a/packages/shared/src/errors/Error.ts +++ b/packages/shared/src/errors/Error.ts @@ -1,5 +1,7 @@ import type { ClerkAPIError, ClerkAPIErrorJSON } from '@clerk/types'; +import { deprecated } from '../utils'; + interface ClerkAPIResponseOptions { data: ClerkAPIErrorJSON[]; status: number; @@ -146,6 +148,7 @@ export class MagicLinkError extends Error { super(code); this.code = code; Object.setPrototypeOf(this, MagicLinkError.prototype); + deprecated('MagicLinkError', 'Use `EmailLinkError` instead.'); } } @@ -164,6 +167,7 @@ export class EmailLinkError extends Error { * @deprecated Use `isEmailLinkError` instead. */ export function isMagicLinkError(err: Error): err is MagicLinkError { + deprecated('isMagicLinkError', 'Use `isEmailLinkError` instead.'); return err instanceof MagicLinkError; } @@ -171,13 +175,19 @@ export function isEmailLinkError(err: Error): err is EmailLinkError { return err instanceof EmailLinkError; } -/** - * @deprecated Use `EmailLinkErrorCode` instead. - */ -export const MagicLinkErrorCode = { +const _MagicLinkErrorCode = { Expired: 'expired', Failed: 'failed', }; +/** + * @deprecated Use `EmailLinkErrorCode` instead. + */ +export const MagicLinkErrorCode = new Proxy(_MagicLinkErrorCode, { + get(target, prop, receiver) { + deprecated('MagicLinkErrorCode', 'Use `EmailLinkErrorCode` instead.'); + return Reflect.get(target, prop, receiver); + }, +}); export const EmailLinkErrorCode = { Expired: 'expired',