Skip to content

Commit 528cdab

Browse files
committed
prettifying
1 parent 2998060 commit 528cdab

File tree

2 files changed

+118
-111
lines changed

2 files changed

+118
-111
lines changed

src/components/app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class App extends Component {
9797
devMode={store.siteURL != null}
9898
onSiteURL={store.siteURL ? this.clearSiteURL : this.handleSiteURL}
9999
/>
100-
)
100+
);
101101
}
102102
if (!store.settings) {
103103
return;

src/netlify-identity.js

+117-110
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,101 @@
1-
import { h, render } from "preact"
2-
import { observe } from "mobx"
3-
import { Provider } from "mobx-preact"
4-
import GoTrue from "gotrue-js"
5-
import App from "./components/app"
6-
import store from "./state/store"
7-
import Controls from "./components/controls"
8-
import modalCSS from "./components/modal.css"
9-
10-
const callbacks = {}
1+
import { h, render } from "preact";
2+
import { observe } from "mobx";
3+
import { Provider } from "mobx-preact";
4+
import GoTrue from "gotrue-js";
5+
import App from "./components/app";
6+
import store from "./state/store";
7+
import Controls from "./components/controls";
8+
import modalCSS from "./components/modal.css";
9+
10+
const callbacks = {};
1111
function trigger(callback) {
12-
;(callbacks[callback] || []).forEach((cb) => {
13-
cb.apply(cb, Array.prototype.slice.call(arguments, 1))
14-
})
12+
(callbacks[callback] || []).forEach(cb => {
13+
cb.apply(cb, Array.prototype.slice.call(arguments, 1));
14+
});
1515
}
1616

1717
const validActions = {
1818
login: true,
1919
signup: true,
2020
error: true
21-
}
21+
};
2222

2323
const netlifyIdentity = {
2424
on: (event, cb) => {
25-
callbacks[event] = callbacks[event] || []
26-
callbacks[event].push(cb)
25+
callbacks[event] = callbacks[event] || [];
26+
callbacks[event].push(cb);
2727
},
28-
open: (action) => {
29-
action = action || "login"
28+
open: action => {
29+
action = action || "login";
3030
if (!validActions[action]) {
31-
throw new Error(`Invalid action for open: ${action}`)
31+
throw new Error(`Invalid action for open: ${action}`);
3232
}
33-
store.openModal(store.user ? "user" : action)
33+
store.openModal(store.user ? "user" : action);
3434
},
3535
close: () => {
36-
store.closeModal()
36+
store.closeModal();
3737
},
3838
currentUser: () => {
39-
return store.gotrue && store.gotrue.currentUser()
39+
return store.gotrue && store.gotrue.currentUser();
4040
},
4141
logout: () => {
42-
return store.logout()
42+
return store.logout();
4343
},
4444
get gotrue() {
4545
if (!store.gotrue) {
46-
store.openModal("login")
46+
store.openModal("login");
4747
}
48-
return store.gotrue
48+
return store.gotrue;
4949
},
50-
init: (options) => {
51-
init(options)
50+
init: options => {
51+
init(options);
5252
},
5353
store
54-
}
54+
};
5555

56-
let queuedIframeStyle = null
56+
let queuedIframeStyle = null;
5757
function setStyle(el, css) {
58-
let style = ""
58+
let style = "";
5959
for (const key in css) {
60-
style += `${key}: ${css[key]}; `
60+
style += `${key}: ${css[key]}; `;
6161
}
6262
if (el) {
63-
el.setAttribute("style", style)
63+
el.setAttribute("style", style);
6464
} else {
65-
queuedIframeStyle = style
65+
queuedIframeStyle = style;
6666
}
6767
}
6868

6969
const localHosts = {
7070
localhost: true,
7171
"127.0.0.1": true,
7272
"0.0.0.0": true
73-
}
73+
};
7474

7575
function instantiateGotrue(APIUrl) {
76-
const isLocal = localHosts[document.location.host.split(":").shift()]
77-
const siteURL = isLocal && localStorage.getItem("netlifySiteURL")
76+
const isLocal = localHosts[document.location.host.split(":").shift()];
77+
const siteURL = isLocal && localStorage.getItem("netlifySiteURL");
7878
if (APIUrl) {
79-
return new GoTrue({ APIUrl, setCookie: !isLocal })
79+
return new GoTrue({ APIUrl, setCookie: !isLocal });
8080
}
8181
if (isLocal && siteURL) {
82-
const parts = [siteURL]
82+
const parts = [siteURL];
8383
if (!siteURL.match(/\/$/)) {
84-
parts.push("/")
84+
parts.push("/");
8585
}
86-
parts.push(".netlify/identity")
87-
store.setSiteURL(siteURL)
88-
return new GoTrue({ APIUrl: parts.join(""), setCookie: !isLocal })
86+
parts.push(".netlify/identity");
87+
store.setSiteURL(siteURL);
88+
return new GoTrue({ APIUrl: parts.join(""), setCookie: !isLocal });
8989
}
9090
if (isLocal) {
91-
return null
91+
return null;
9292
}
9393

94-
return new GoTrue({ setCookie: !isLocal })
94+
return new GoTrue({ setCookie: !isLocal });
9595
}
9696

97-
let root
98-
let iframe
97+
let root;
98+
let iframe;
9999
const iframeStyle = {
100100
position: "fixed",
101101
top: 0,
@@ -107,129 +107,136 @@ const iframeStyle = {
107107
background: "transparent",
108108
display: "none",
109109
"z-index": 99
110-
}
110+
};
111111

112112
observe(store.modal, "isOpen", () => {
113113
if (!store.settings) {
114-
store.loadSettings()
114+
store.loadSettings();
115115
}
116116
setStyle(iframe, {
117117
...iframeStyle,
118118
display: store.modal.isOpen ? "block !important" : "none"
119-
})
119+
});
120120
if (store.modal.isOpen) {
121-
trigger("open", store.modal.page)
121+
trigger("open", store.modal.page);
122122
} else {
123-
trigger("close")
123+
trigger("close");
124124
}
125-
})
125+
});
126126

127127
observe(store, "siteURL", () => {
128128
if (store.siteURL === null || store.siteURL === undefined) {
129-
localStorage.removeItem("netlifySiteURL")
129+
localStorage.removeItem("netlifySiteURL");
130130
} else {
131-
localStorage.setItem("netlifySiteURL", store.siteURL)
131+
localStorage.setItem("netlifySiteURL", store.siteURL);
132132
}
133-
store.init(instantiateGotrue(), true)
134-
})
133+
store.init(instantiateGotrue(), true);
134+
});
135135

136136
observe(store, "user", () => {
137137
if (store.user) {
138-
trigger("login", store.user)
138+
trigger("login", store.user);
139139
} else {
140-
trigger("logout")
140+
trigger("logout");
141141
}
142-
})
142+
});
143143

144144
observe(store, "gotrue", () => {
145-
store.gotrue && trigger("init", store.gotrue.currentUser())
146-
})
145+
store.gotrue && trigger("init", store.gotrue.currentUser());
146+
});
147147

148148
observe(store, "error", () => {
149-
trigger("error", store.error)
150-
})
149+
trigger("error", store.error);
150+
});
151151

152-
const routes = /(confirmation|invite|recovery|email_change)_token=([^&]+)/
153-
const errorRoute = /error=access_denied&error_description=403/
154-
const accessTokenRoute = /access_token=/
152+
const routes = /(confirmation|invite|recovery|email_change)_token=([^&]+)/;
153+
const errorRoute = /error=access_denied&error_description=403/;
154+
const accessTokenRoute = /access_token=/;
155155

156156
function runRoutes() {
157-
const hash = (document.location.hash || "").replace(/^#\/?/, "")
157+
const hash = (document.location.hash || "").replace(/^#\/?/, "");
158158
if (!hash) {
159-
return
159+
return;
160160
}
161161

162-
const m = hash.match(routes)
162+
const m = hash.match(routes);
163163
if (m) {
164-
store.verifyToken(m[1], m[2])
165-
document.location.hash = ""
164+
store.verifyToken(m[1], m[2]);
165+
document.location.hash = "";
166166
}
167167

168-
const em = hash.match(errorRoute)
168+
const em = hash.match(errorRoute);
169169
if (em) {
170-
store.openModal("signup")
171-
document.location.hash = ""
170+
store.openModal("signup");
171+
document.location.hash = "";
172172
}
173173

174-
const am = hash.match(accessTokenRoute)
174+
const am = hash.match(accessTokenRoute);
175175
if (am) {
176-
const params = {}
177-
hash.split("&").forEach((pair) => {
178-
const [key, value] = pair.split("=")
179-
params[key] = value
180-
})
176+
const params = {};
177+
hash.split("&").forEach(pair => {
178+
const [key, value] = pair.split("=");
179+
params[key] = value;
180+
});
181181
if (!!document && params["access_token"]) {
182-
document.cookie = `nf_jwt=${params["access_token"]}`
182+
document.cookie = `nf_jwt=${params["access_token"]}`;
183183
}
184-
document.location.hash = ""
185-
store.openModal("login")
186-
store.completeExternalLogin(params)
184+
document.location.hash = "";
185+
store.openModal("login");
186+
store.completeExternalLogin(params);
187187
}
188188
}
189189

190190
function init(options = {}) {
191-
const { APIUrl, logo = true, namePlaceholder } = options
192-
const controlEls = document.querySelectorAll("[data-netlify-identity-menu],[data-netlify-identity-button]")
193-
Array.prototype.slice.call(controlEls).forEach((el) => {
194-
let controls = null
195-
const mode = el.getAttribute("data-netlify-identity-menu") === null ? "button" : "menu"
191+
const { APIUrl, logo = true, namePlaceholder } = options;
192+
const controlEls = document.querySelectorAll(
193+
"[data-netlify-identity-menu],[data-netlify-identity-button]"
194+
);
195+
Array.prototype.slice.call(controlEls).forEach(el => {
196+
let controls = null;
197+
const mode =
198+
el.getAttribute("data-netlify-identity-menu") === null
199+
? "button"
200+
: "menu";
196201
render(
197202
<Provider store={store}>
198203
<Controls mode={mode} text={el.innerText.trim()} />
199204
</Provider>,
200205
el,
201206
controls
202-
)
203-
})
204-
205-
store.init(instantiateGotrue(APIUrl))
206-
store.modal.logo = logo
207-
store.setNamePlaceholder(namePlaceholder)
208-
iframe = document.createElement("iframe")
209-
iframe.id = "netlify-identity-widget"
207+
);
208+
});
209+
210+
store.init(instantiateGotrue(APIUrl));
211+
store.modal.logo = logo;
212+
store.setNamePlaceholder(namePlaceholder);
213+
iframe = document.createElement("iframe");
214+
iframe.id = "netlify-identity-widget";
210215
iframe.onload = () => {
211-
const styles = iframe.contentDocument.createElement("style")
212-
styles.innerHTML = modalCSS.toString()
213-
iframe.contentDocument.head.appendChild(styles)
216+
const styles = iframe.contentDocument.createElement("style");
217+
styles.innerHTML = modalCSS.toString();
218+
iframe.contentDocument.head.appendChild(styles);
214219
root = render(
215220
<Provider store={store}>
216221
<App />
217222
</Provider>,
218223
iframe.contentDocument.body,
219224
root
220-
)
221-
runRoutes()
222-
}
223-
setStyle(iframe, iframeStyle)
224-
iframe.src = "about:blank"
225-
const container = options.container ? document.querySelector(options.container) : document.body
226-
container.appendChild(iframe)
225+
);
226+
runRoutes();
227+
};
228+
setStyle(iframe, iframeStyle);
229+
iframe.src = "about:blank";
230+
const container = options.container
231+
? document.querySelector(options.container)
232+
: document.body;
233+
container.appendChild(iframe);
227234
/* There's a certain case where we might have called setStyle before the iframe was ready.
228235
Make sure we take the last style and apply it */
229236
if (queuedIframeStyle) {
230-
iframe.setAttribute("style", queuedIframeStyle)
231-
queuedIframeStyle = null
237+
iframe.setAttribute("style", queuedIframeStyle);
238+
queuedIframeStyle = null;
232239
}
233240
}
234241

235-
export default netlifyIdentity
242+
export default netlifyIdentity;

0 commit comments

Comments
 (0)