Skip to content

Commit 4e94789

Browse files
committed
Add APIUrl option to module API
1 parent 36d8789 commit 4e94789

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const netlifyIdentity = require("netlify-identity-widget");
9595

9696
netlifyIdentity.init({
9797
container: "#netlify-modal" // defaults to document.body,
98+
APIUrl: "https://some-identity-instance.example.com" // Set an absolute URL for the identity endpoint
9899
});
99100

100101
netlifyIdentity.open(); // open the modal

src/netlify-identity.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@ const localHosts = {
7171
"0.0.0.0": true
7272
};
7373

74-
function instantiateGotrue() {
74+
function instantiateGotrue(APIUrl) {
7575
const isLocal = localHosts[document.location.host.split(":").shift()];
7676
const siteURL = isLocal && localStorage.getItem("netlifySiteURL");
77+
if (APIUrl) {
78+
return new GoTrue({ APIUrl, setCookie: !isLocal });
79+
}
7780
if (isLocal && siteURL) {
7881
const parts = [siteURL];
7982
if (!siteURL.match(/\/$/)) {
@@ -175,8 +178,8 @@ function runRoutes() {
175178
}
176179
}
177180

178-
function init(options) {
179-
options = options || {};
181+
function init(options = {}) {
182+
const { APIUrl } = options;
180183
const controlEls = document.querySelectorAll(
181184
"[data-netlify-identity-menu],[data-netlify-identity-button]"
182185
);
@@ -195,8 +198,8 @@ function init(options) {
195198
);
196199
});
197200

198-
store.init(instantiateGotrue());
199-
if (options.hasOwnProperty("logo")) store.modal.logo = options.logo;
201+
store.init(instantiateGotrue(APIUrl));
202+
if (options.logo) store.modal.logo = options.logo;
200203
iframe = document.createElement("iframe");
201204
iframe.id = "netlify-identity-widget";
202205
iframe.onload = () => {

0 commit comments

Comments
 (0)