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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV-574 DEV-635 small bug fixes #73

Merged
merged 5 commits into from
Sep 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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