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
5 changes: 5 additions & 0 deletions .changeset/dry-shrimps-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/elements": patch
---

feat(elements): Add support for sign in with email_link via redirect_url
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ export const SignInRouterMachine = setup({
input: ({ context, self }) => ({
formRef: context.formRef,
parent: self,
basePath: context.router?.basePath,
}),
onDone: {
actions: 'raiseNext',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import type {
import type { DoneActorEvent } from 'xstate';
import { assign, fromPromise, log, sendTo, setup } from 'xstate';

import { RESENDABLE_COUNTDOWN_DEFAULT } from '~/internals/constants';
import {
MAGIC_LINK_VERIFY_PATH_ROUTE,
RESENDABLE_COUNTDOWN_DEFAULT,
SIGN_IN_DEFAULT_BASE_PATH,
} from '~/internals/constants';
import { ClerkElementsRuntimeError } from '~/internals/errors';
import type { FormFields } from '~/internals/machines/form';
import type { SignInStrategyName, WithParams } from '~/internals/machines/shared';
Expand Down Expand Up @@ -179,6 +183,7 @@ const SignInVerificationMachine = setup({
id: SignInVerificationMachineId,
context: ({ input }) => ({
currentFactor: null,
basePath: input.basePath || SIGN_IN_DEFAULT_BASE_PATH,
formRef: input.formRef,
loadingStep: 'verifications',
parent: input.parent,
Expand Down Expand Up @@ -237,7 +242,10 @@ const SignInVerificationMachine = setup({
input: ({ context }) => ({
parent: context.parent,
resendable: context.resendable,
params: context.currentFactor as PrepareFirstFactorParams,
params: {
...context.currentFactor,
redirectUrl: `${window.location.origin}${context.basePath}${MAGIC_LINK_VERIFY_PATH_ROUTE}`,
Copy link
Member Author

Choose a reason for hiding this comment

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

It might make sense for this URL to be built somewhere else. In clerk-js we have a buildURL helper that handles appending the origin based on the routing type.

} as PrepareFirstFactorParams,
}),
onDone: {
actions: 'resendableReset',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type SignInVerificationEvents =
export interface SignInVerificationInput {
formRef: ActorRefFrom<typeof FormMachine>;
parent: SignInRouterMachineActorRef;
basePath?: string;
}

// ---------------------------------- Context ---------------------------------- //
Expand All @@ -51,6 +52,7 @@ export interface SignInVerificationContext {
registeredStrategies: Set<SignInStrategyName>;
resendable: boolean;
resendableAfter: number;
basePath?: string;
}

// ---------------------------------- Delays ---------------------------------- //
Expand Down