Skip to content

Commit 192da2b

Browse files
author
sw-yx
committed
remove window reference
1 parent a0fe34f commit 192da2b

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/components/providers.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ import React from "react"
22
import { useIdentityContext, SettingContext } from "../context"
33
import { Settings } from "react-netlify-identity"
44

5-
6-
7-
const isLocalhost = Boolean(
8-
window.location.hostname === 'localhost' ||
9-
// [::1] is the IPv6 localhost address.
10-
window.location.hostname === '[::1]' ||
11-
// 127.0.0.1/8 is considered localhost for IPv4.
12-
window.location.hostname.match(
13-
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
5+
const isLocalhost =
6+
window !== undefined &&
7+
Boolean(
8+
window.location.hostname === "localhost" ||
9+
// [::1] is the IPv6 localhost address.
10+
window.location.hostname === "[::1]" ||
11+
// 127.0.0.1/8 is considered localhost for IPv4.
12+
window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
1413
)
15-
);
1614

1715
export function Providers() {
1816
const setting = React.useContext(SettingContext)
@@ -23,7 +21,9 @@ export function Providers() {
2321
if (!hasProviders) return null
2422
return (
2523
<div className="providersGroup">
26-
{isLocalhost && <pre>⚠️Testing providers on localhost won't work because OAuth redirects to your production site</pre>}
24+
{isLocalhost && (
25+
<pre>⚠️Testing providers on localhost won't work because OAuth redirects to your production site</pre>
26+
)}
2727
<hr className="hr" />
2828
<ProviderButton setting={setting} provider="Google" />
2929
<ProviderButton setting={setting} provider="GitHub" />

0 commit comments

Comments
 (0)