Skip to content

Commit

Permalink
DEV-1444 Read linkType from query params and pass to core (#114)
Browse files Browse the repository at this point in the history
* Read link type from query params and pass to core

* Override the userfrontSource param to core

* Update userfront core version
  • Loading branch information
drbrady8800 authored Jul 26, 2024
1 parent 6e2ee9a commit d63e15d
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 37 deletions.
68 changes: 34 additions & 34 deletions 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
Expand Up @@ -55,7 +55,7 @@
"dependencies": {
"@r2wc/react-to-web-component": "^2.0.2",
"@react-hook/resize-observer": "^1.2.6",
"@userfront/core": "^0.6.8",
"@userfront/core": "1.0.0",
"@xstate/react": "3.0.1",
"lodash": "^4.17.21",
"react-icons": "^4.4.0",
Expand Down
19 changes: 18 additions & 1 deletion package/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -47,4 +64,4 @@ export const _devTools = {
overrideUserfrontSingleton,
};

export default Userfront;
export default UserfrontProxy;
2 changes: 2 additions & 0 deletions package/src/models/config/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ export const readQueryParams = assign((context: AuthContext<View>) => {
}
const uuid = getQueryAttr("uuid");
const token = getQueryAttr("token");
const linkType = getQueryAttr("type");
return {
query: {
uuid,
token,
linkType,
isValid: true,
},
};
Expand Down
6 changes: 5 additions & 1 deletion package/src/models/forms/universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -696,6 +699,7 @@ const universalMachineConfig: AuthMachineConfig = {
method: "link",
token: context.query.token,
uuid: context.query.uuid,
linkType: context.query.linkType,
redirect: context.config?.redirect,
},
],
Expand Down
1 change: 1 addition & 0 deletions package/src/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export type View =
export type Query = {
token?: string;
uuid?: string;
linkType?: string;
isValid?: boolean;
};

Expand Down

0 comments on commit d63e15d

Please sign in to comment.