Skip to content

Commit

Permalink
refactor(elements): Split out contexts and hooks (#2695)
Browse files Browse the repository at this point in the history
* refactor(elements): Split out Sign In

* refactor(elements): Standardize SignIn context

* refactor(elements): Split out Sign Up

* chore(elements): Remove temp router machine

* chore(elements): Add changeset
  • Loading branch information
tmilewski authored Jan 31, 2024
1 parent 7f751c4 commit ff19827
Show file tree
Hide file tree
Showing 30 changed files with 376 additions and 376 deletions.
2 changes: 2 additions & 0 deletions .changeset/wise-drinks-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use client';

import { SignedIn } from '@clerk/clerk-react';
import { useSignInFlow, useSignInFlowSelector } from '@clerk/elements/sign-in';
import { useSignInActorRef_internal, useSignInSelector_internal } from '@clerk/elements/sign-in';
import { SignOutButton } from '@clerk/nextjs';

import { Button } from './design';

function SignInActiveState() {
const activeState = useSignInFlowSelector(state => state.value);
const activeState = useSignInSelector_internal(state => state.value);
const state = activeState ? (typeof activeState === 'string' ? activeState : JSON.stringify({ ...activeState })) : '';

return (
Expand All @@ -18,7 +18,7 @@ function SignInActiveState() {
}

export function SignInLogButtons() {
const ref = useSignInFlow();
const ref = useSignInActorRef_internal();

return (
<>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use client';

import { SignedIn } from '@clerk/clerk-react';
import { useSignUpFlow, useSignUpFlowSelector } from '@clerk/elements/sign-up';
import { useSignUpActorRef_internal, useSignUpSelector_internal } from '@clerk/elements/sign-up';
import { SignOutButton } from '@clerk/nextjs';

import { Button } from './design';

function SignUpActiveState() {
const activeState = useSignUpFlowSelector(state => state.value);
const activeState = useSignUpSelector_internal(state => state.value);
const state = activeState ? (typeof activeState === 'string' ? activeState : JSON.stringify({ ...activeState })) : '';

return (
Expand All @@ -18,7 +18,7 @@ function SignUpActiveState() {
}

export function SignUpLogButtons() {
const ref = useSignUpFlow();
const ref = useSignUpActorRef_internal();

return (
<>
Expand Down
193 changes: 0 additions & 193 deletions packages/elements/src/internals/machines/sign-in/sign-in.context.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export interface SignInMachineInput {
router: ClerkRouter;
}

export type SignInMachineTags = 'state:start' | 'state:first-factor' | 'state:second-factor' | 'external';

export type SignInMachineEvents =
| ErrorActorEvent
| { type: 'AUTHENTICATE.OAUTH'; strategy: OAuthStrategy }
Expand All @@ -62,6 +64,7 @@ export interface SignInMachineTypes {
context: SignInMachineContext;
input: SignInMachineInput;
events: SignInMachineEvents;
tags: SignInMachineTags;
}

export const SignInMachine = setup({
Expand Down Expand Up @@ -237,6 +240,7 @@ export const SignInMachine = setup({
},
Start: {
id: 'Start',
tags: 'state:start',
description: 'The intial state of the sign-in flow.',
initial: 'AwaitingInput',
on: {
Expand Down Expand Up @@ -291,6 +295,7 @@ export const SignInMachine = setup({
},
},
FirstFactor: {
tags: 'state:first-factor',
initial: 'DeterminingState',
entry: 'assignStartingFirstFactor',
onDone: [
Expand Down Expand Up @@ -378,6 +383,7 @@ export const SignInMachine = setup({
},
},
SecondFactor: {
tags: 'state:second-factor',
initial: 'DeterminingState',
entry: 'assignStartingSecondFactor',
onDone: [
Expand Down
Loading

0 comments on commit ff19827

Please sign in to comment.