Skip to content

Commit

Permalink
Override the userfrontSource param to core
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrady8800 committed Jul 26, 2024
1 parent a4a116f commit fdb877a
Showing 2 changed files with 22 additions and 2 deletions.
19 changes: 18 additions & 1 deletion package/src/index.js
Original file line number Diff line number Diff line change
@@ -24,6 +24,23 @@ Userfront.build = (toolId) => {
See https://userfront.com/dashboard/toolkit for more information about upgrading to the new toolkit.`);
};

/**
* Override Userfront.init to pass toolkit userfrontSource param into it
*/
const UserfrontProxy = new Proxy(Userfront, {
get(target, prop) {
if (prop === "init") {
return (tenantId, options = {}) => {
Userfront.init(tenantId, {
...options,
userfrontSource: "toolkit",
});
};
}
return target[prop];
},
});

/*
* Dev tools.
* You probably only want these if you're developing this library.
@@ -47,4 +64,4 @@ export const _devTools = {
overrideUserfrontSingleton,
};

export default Userfront;
export default UserfrontProxy;
5 changes: 4 additions & 1 deletion package/src/models/forms/universal.ts
Original file line number Diff line number Diff line change
@@ -329,7 +329,10 @@ const universalMachineConfig: AuthMachineConfig = {
// @ts-ignore
callUserfrontSync({
method: "init",
args: [context.config.tenantId!],
args: [
context.config.tenantId!,
{ options: { userfrontSource: "toolkit" } },
],
});
return context.config.tenantId;
},

0 comments on commit fdb877a

Please sign in to comment.