Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit d63e15d

Browse files
authored
DEV-1444 Read linkType from query params and pass to core (#114)
* Read link type from query params and pass to core * Override the userfrontSource param to core * Update userfront core version
1 parent 6e2ee9a commit d63e15d

6 files changed

Lines changed: 61 additions & 37 deletions

File tree

package-lock.json

Lines changed: 34 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"dependencies": {
5656
"@r2wc/react-to-web-component": "^2.0.2",
5757
"@react-hook/resize-observer": "^1.2.6",
58-
"@userfront/core": "^0.6.8",
58+
"@userfront/core": "1.0.0",
5959
"@xstate/react": "3.0.1",
6060
"lodash": "^4.17.21",
6161
"react-icons": "^4.4.0",

package/src/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ Userfront.build = (toolId) => {
2424
See https://userfront.com/dashboard/toolkit for more information about upgrading to the new toolkit.`);
2525
};
2626

27+
/**
28+
* Override Userfront.init to pass toolkit userfrontSource param into it
29+
*/
30+
const UserfrontProxy = new Proxy(Userfront, {
31+
get(target, prop) {
32+
if (prop === "init") {
33+
return (tenantId, options = {}) => {
34+
Userfront.init(tenantId, {
35+
...options,
36+
userfrontSource: "toolkit",
37+
});
38+
};
39+
}
40+
return target[prop];
41+
},
42+
});
43+
2744
/*
2845
* Dev tools.
2946
* You probably only want these if you're developing this library.
@@ -47,4 +64,4 @@ export const _devTools = {
4764
overrideUserfrontSingleton,
4865
};
4966

50-
export default Userfront;
67+
export default UserfrontProxy;

package/src/models/config/actions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ export const readQueryParams = assign((context: AuthContext<View>) => {
8282
}
8383
const uuid = getQueryAttr("uuid");
8484
const token = getQueryAttr("token");
85+
const linkType = getQueryAttr("type");
8586
return {
8687
query: {
8788
uuid,
8889
token,
90+
linkType,
8991
isValid: true,
9092
},
9193
};

package/src/models/forms/universal.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,10 @@ const universalMachineConfig: AuthMachineConfig = {
329329
// @ts-ignore
330330
callUserfrontSync({
331331
method: "init",
332-
args: [context.config.tenantId!],
332+
args: [
333+
context.config.tenantId!,
334+
{ options: { userfrontSource: "toolkit" } },
335+
],
333336
});
334337
return context.config.tenantId;
335338
},
@@ -696,6 +699,7 @@ const universalMachineConfig: AuthMachineConfig = {
696699
method: "link",
697700
token: context.query.token,
698701
uuid: context.query.uuid,
702+
linkType: context.query.linkType,
699703
redirect: context.config?.redirect,
700704
},
701705
],

package/src/models/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export type View =
150150
export type Query = {
151151
token?: string;
152152
uuid?: string;
153+
linkType?: string;
153154
isValid?: boolean;
154155
};
155156

0 commit comments

Comments
 (0)