Skip to content

Commit

Permalink
Merge pull request #73 from userfront/dev-574-635-fixes
Browse files Browse the repository at this point in the history
DEV-574 DEV-635 small bug fixes
  • Loading branch information
RJFelix authored Sep 6, 2023
2 parents 7944844 + 009a57e commit 54e849f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 7 deletions.
54 changes: 53 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@userfront/toolkit",
"version": "1.0.0",
"version": "1.0.1-alpha.1",
"description": "Bindings and components for authentication with Userfront with React, Vue, other frameworks, and plain JS + HTML",
"type": "module",
"directories": {
Expand Down
2 changes: 1 addition & 1 deletion package/src/forms/UniversalForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ const componentForStep = (state) => {
isLoading: true,
},
};
case "password.showPasswordSuccess":
case "password.showPasswordSet":
return {
title: strings[type].done,
Component: Success,
Expand Down
3 changes: 2 additions & 1 deletion package/src/models/views/setUpTotp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ const setUpTotpConfig: AuthMachineConfig = {
cond: "secondFactorRequiredFromView",
},
// We're signed in.
// Core JS redirects as appropriate here.
// Instruct CoreJS to redirect as appropriate here
// Show the "verified" view in case we don't redirect.
{
actions: "redirectIfLoggedIn",
target: "showTotpSetupComplete",
},
],
Expand Down
18 changes: 17 additions & 1 deletion package/src/services/userfront.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ declare module "@userfront/core" {
}

let singleton = Userfront;
let isSingletonOverridden = false;

/**
* Override the Userfront singleton imported from @userfront/core with an object of your choice.
Expand All @@ -22,6 +23,7 @@ let singleton = Userfront;
*/
export const overrideUserfrontSingleton = (newSingleton: any) => {
singleton = newSingleton as typeof Userfront;
isSingletonOverridden = true;
};

// A type with the keys of all functions in Type
Expand Down Expand Up @@ -110,7 +112,21 @@ export const callUserfront = async ({ method, args = [] }: CallUserfront) => {
return Promise.reject();
}
try {
return await (<any>_method)(...args);
const res = await (<any>_method)(...args);
// Workaround to avoid flickering when CoreJS redirects:
// wait for the current iteration of the event loop to finish,
// and for the async task queue to finish,
// and for the NEXT event loop cycle to finish,
// then return.
// TODO DEV-658 fix this in a nicer and more reliable way
if (isSingletonOverridden) {
// Don't wait if we've overridden the CoreJS singleton,
// i.e. mocked it out for tests.
return res;
}
return new Promise((resolve) => {
setTimeout(() => resolve(res), 1);
});
} catch (err: any) {
console.warn(
`Method ${method} on Userfront object threw. Error: ${err.message}`
Expand Down

2 comments on commit 54e849f

@vercel
Copy link

@vercel vercel bot commented on 54e849f Sep 6, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 54e849f Sep 6, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.