Skip to content

Commit

Permalink
Accept mode for DemoForm
Browse files Browse the repository at this point in the history
  • Loading branch information
RJFelix committed Feb 2, 2024
1 parent 0711dce commit ce4a384
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 7 additions & 2 deletions package/src/packaged-forms/DemoForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ const defaultDemoAuthFlow = {
* @param {boolean=} props.theme.options.gradientButtons - add an interactive gradient to buttons
* @param {boolean=} props.theme.options.hideSecuredMessage - hide the "secured by Userfront" message
*/
const DemoForm = ({ type, theme, authFlow = defaultDemoAuthFlow }) => {
const DemoForm = ({
type,
theme,
authFlow = defaultDemoAuthFlow,
mode = "live",
}) => {
context.config.type = type;

const mockUserfront = useMockUserfront({ authFlow });
const mockUserfront = useMockUserfront({ authFlow, mode });

const machine = SignupFormModel;
const machineOptions = {};
Expand Down
13 changes: 7 additions & 6 deletions package/src/utils/mockUserfront.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ const mockUserfrontResponses = {
};

class MockUserfront {
constructor({ authFlow }) {
constructor({ authFlow, mode }) {
this.store = {
tenantId: "demo1234",
tokens: {},
Expand All @@ -374,6 +374,7 @@ class MockUserfront {
this.requireMfaSetup = false;
this.isAwaitingSecondFactor = false;
this.authFlow = authFlow;
this.mode = mode;

this.login = this.login.bind(this);
this.signup = this.signup.bind(this);
Expand Down Expand Up @@ -456,19 +457,19 @@ class MockUserfront {
const modeResponse = mockUserfrontResponses.setMode();
if (this.authFlow) {
return {
mode: "live",
mode: this.mode,
authentication: this.authFlow,
};
}
return modeResponse;
}
}

const createMockUserfront = ({ authFlow } = {}) =>
new MockUserfront({ authFlow });
const createMockUserfront = ({ authFlow, mode = "live" } = {}) =>
new MockUserfront({ authFlow, mode });

export const useMockUserfront = ({ authFlow } = {}) => {
const mockUserfront = createMockUserfront({ authFlow });
export const useMockUserfront = ({ authFlow, mode = "live" } = {}) => {
const mockUserfront = createMockUserfront({ authFlow, mode });
overrideUserfrontSingleton(mockUserfront);
return mockUserfront;
};
Expand Down

0 comments on commit ce4a384

Please sign in to comment.