Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(*): Rename refs of MagicLink to EmailLink - deprecation warnings #1836

Merged
merged 4 commits into from
Oct 9, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/hip-bees-warn.md
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 2 additions & 0 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,8 @@ export default class Clerk implements ClerkInterface {
params: HandleMagicLinkVerificationParams,
customNavigate?: (to: string) => Promise<unknown>,
): Promise<unknown> => {
deprecated('handleMagicLinkVerification', 'Use `handleEmailLinkVerification` instead.');

if (!this.client) {
return;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/clerk-js/src/core/resources/EmailAddress.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Poller } from '@clerk/shared';
import { deprecated, Poller } from '@clerk/shared';
import type {
AttemptEmailAddressVerificationParams,
CreateEmailLinkFlowReturn,
Expand Down Expand Up @@ -52,6 +52,8 @@ export class EmailAddress extends BaseResource implements EmailAddressResource {
* @deprecated Use `createEmailLinkFlow` instead.
*/
createMagicLinkFlow = (): CreateMagicLinkFlowReturn<StartMagicLinkFlowParams, EmailAddressResource> => {
deprecated('createMagicLinkFlow', 'Use `createEmailLinkFlow` instead.');

const { run, stop } = Poller();

const startMagicLinkFlow = async ({ redirectUrl }: StartMagicLinkFlowParams): Promise<EmailAddressResource> => {
Expand Down
4 changes: 3 additions & 1 deletion packages/clerk-js/src/core/resources/SignIn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepSnakeToCamel, Poller } from '@clerk/shared';
import { deepSnakeToCamel, deprecated, Poller } from '@clerk/shared';
import type {
AttemptFirstFactorParams,
AttemptSecondFactorParams,
Expand Down Expand Up @@ -125,6 +125,8 @@ export class SignIn extends BaseResource implements SignInResource {
* @deprecated Use `createEmailLinkFlow` instead.
*/
createMagicLinkFlow = (): CreateMagicLinkFlowReturn<SignInStartMagicLinkFlowParams, SignInResource> => {
deprecated('createMagicLinkFlow', 'Use `createEmailLinkFlow` instead.');

const { run, stop } = Poller();

const startMagicLinkFlow = async ({
Expand Down
2 changes: 2 additions & 0 deletions packages/clerk-js/src/core/resources/SignUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export class SignUp extends BaseResource implements SignUpResource {
* @deprecated Use `createEmailLinkFlow` instead.
*/
createMagicLinkFlow = (): CreateMagicLinkFlowReturn<StartMagicLinkFlowParams, SignUpResource> => {
deprecated('createMagicLinkFlow', 'Use `createEmailLinkFlow` instead.');

const { run, stop } = Poller();

const startMagicLinkFlow = async ({ redirectUrl }: StartMagicLinkFlowParams): Promise<SignUpResource> => {
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/hooks/useMagicLink.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { deprecated } from '@clerk/shared';
import type {
CreateMagicLinkFlowReturn,
EmailAddressResource,
Expand Down Expand Up @@ -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(() => {
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/isomorphicClerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ export default class IsomorphicClerk {
* @deprecated Use `handleEmailLinkVerification` instead.
*/
handleMagicLinkVerification = async (params: HandleMagicLinkVerificationParams): Promise<void> => {
deprecated('handleMagicLinkVerification', 'Use `handleEmailLinkVerification` instead.');
const callback = () => this.clerkjs?.handleMagicLinkVerification(params);
if (this.clerkjs && this.#loaded) {
return callback() as Promise<void>;
Expand Down
18 changes: 14 additions & 4 deletions packages/shared/src/errors/Error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { ClerkAPIError, ClerkAPIErrorJSON } from '@clerk/types';

import { deprecated } from '../utils';

interface ClerkAPIResponseOptions {
data: ClerkAPIErrorJSON[];
status: number;
Expand Down Expand Up @@ -146,6 +148,7 @@ export class MagicLinkError extends Error {
super(code);
this.code = code;
Object.setPrototypeOf(this, MagicLinkError.prototype);
deprecated('MagicLinkError', 'Use `EmailLinkError` instead.');
}
}

Expand All @@ -164,20 +167,27 @@ 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;
}

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',
Expand Down