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

Commit 03581dc

Browse files
authored
Merge pull request #78 from userfront/ssr-web-component-compat
Check that we're in the browser before registering web components
2 parents ea14b06 + 96e675d commit 03581dc

4 files changed

Lines changed: 57 additions & 53 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/package-lock.json

Lines changed: 2 additions & 2 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
@@ -1,6 +1,6 @@
11
{
22
"name": "@userfront/toolkit",
3-
"version": "1.0.2-alpha.9",
3+
"version": "1.0.2-alpha.11",
44
"description": "Bindings and components for authentication with Userfront with React, Vue, other frameworks, and plain JS + HTML",
55
"type": "module",
66
"directories": {

package/src/web-component.js

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,57 +13,61 @@ if (typeof window === "object" && !window.Userfront) {
1313
window.Userfront = Userfront;
1414
}
1515

16-
/* Define the <foo-form> custom elements */
17-
customElements.define(
18-
"signup-form",
19-
r2wc(SignupForm, {
20-
props: {
21-
tenantId: "string",
22-
flow: "json",
23-
compact: "boolean",
24-
redirect: "string",
25-
redirectOnLoadIfLoggedIn: "boolean",
26-
xstateDevTools: "boolean",
27-
},
28-
})
29-
);
16+
// Register custom elements if we're in the browser.
17+
// (Skip for SSR scenarios.)
18+
if (typeof window === "object" && window.customElements) {
19+
/* Define the <foo-form> custom elements */
20+
customElements.define(
21+
"signup-form",
22+
r2wc(SignupForm, {
23+
props: {
24+
tenantId: "string",
25+
flow: "json",
26+
compact: "boolean",
27+
redirect: "string",
28+
redirectOnLoadIfLoggedIn: "boolean",
29+
xstateDevTools: "boolean",
30+
},
31+
})
32+
);
3033

31-
customElements.define(
32-
"login-form",
33-
r2wc(LoginForm, {
34-
props: {
35-
tenantId: "string",
36-
flow: "json",
37-
compact: "boolean",
38-
redirect: "string",
39-
redirectOnLoadIfLoggedIn: "boolean",
40-
xstateDevTools: "boolean",
41-
},
42-
})
43-
);
34+
customElements.define(
35+
"login-form",
36+
r2wc(LoginForm, {
37+
props: {
38+
tenantId: "string",
39+
flow: "json",
40+
compact: "boolean",
41+
redirect: "string",
42+
redirectOnLoadIfLoggedIn: "boolean",
43+
xstateDevTools: "boolean",
44+
},
45+
})
46+
);
4447

45-
customElements.define(
46-
"password-reset-form",
47-
r2wc(PasswordResetForm, {
48-
props: {
49-
tenantId: "string",
50-
flow: "json",
51-
compact: "boolean",
52-
redirect: "string",
53-
redirectOnLoadIfLoggedIn: "boolean",
54-
xstateDevTools: "boolean",
55-
},
56-
})
57-
);
48+
customElements.define(
49+
"password-reset-form",
50+
r2wc(PasswordResetForm, {
51+
props: {
52+
tenantId: "string",
53+
flow: "json",
54+
compact: "boolean",
55+
redirect: "string",
56+
redirectOnLoadIfLoggedIn: "boolean",
57+
xstateDevTools: "boolean",
58+
},
59+
})
60+
);
5861

59-
customElements.define(
60-
"logout-button",
61-
r2wc(LogoutButton, {
62-
props: {
63-
disabled: "boolean",
64-
redirect: "string",
65-
},
66-
})
67-
);
62+
customElements.define(
63+
"logout-button",
64+
r2wc(LogoutButton, {
65+
props: {
66+
disabled: "boolean",
67+
redirect: "string",
68+
},
69+
})
70+
);
71+
}
6872

6973
export default Userfront;

0 commit comments

Comments
 (0)