Skip to content

Commit d2d553f

Browse files
author
sw-yx
committed
add localhost warning to providers
1 parent 7ca48a7 commit d2d553f

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

example/src/App.tsx

+13-12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import "./App.css"
33
import { IdentityModal, useNetlifyIdentity, IdentityContextProvider } from "react-netlify-identity-widget"
44
import "react-netlify-identity-widget/styles.css"
55

6+
7+
68
function App() {
79
const [dialog, setDialog] = React.useState(false)
810
const identity = useNetlifyIdentity("https://react-netlify-identity-widget.netlify.com")
@@ -24,21 +26,20 @@ function App() {
2426
>
2527
LOG OUT
2628
</button>
27-
<IdentityModal showDialog={dialog} onCloseDialog={() => setDialog(false)} />
2829
</>
2930
) : (
30-
<>
31-
<h1> hello! try logging in! </h1>
32-
<button
33-
className="btn"
34-
style={{ maxWidth: 400, background: "darkgreen" }}
35-
onClick={() => setDialog(true)}
36-
>
37-
LOG IN
31+
<>
32+
<h1> hello! try logging in! </h1>
33+
<button
34+
className="btn"
35+
style={{ maxWidth: 400, background: "darkgreen" }}
36+
onClick={() => setDialog(true)}
37+
>
38+
LOG IN
3839
</button>
39-
<IdentityModal showDialog={dialog} onCloseDialog={() => setDialog(false)} />
40-
</>
41-
)}
40+
</>
41+
)}
42+
<IdentityModal showDialog={dialog} onCloseDialog={() => setDialog(false)} />
4243
<h3>
4344
Or{" "}
4445
<a

src/components/providers.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import React from "react"
22
import { useIdentityContext, SettingContext } from "../context"
33
import { Settings } from "react-netlify-identity"
4+
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}$/
14+
)
15+
);
16+
417
export function Providers() {
518
const setting = React.useContext(SettingContext)
619
const hasProviders =
@@ -10,6 +23,7 @@ export function Providers() {
1023
if (!hasProviders) return null
1124
return (
1225
<div className="providersGroup">
26+
{isLocalhost && <pre>⚠️Testing providers on localhost won't work because OAuth redirects to your production site</pre>}
1327
<hr className="hr" />
1428
<ProviderButton setting={setting} provider="Google" />
1529
<ProviderButton setting={setting} provider="GitHub" />

0 commit comments

Comments
 (0)