Make Neltify CMS work with Netlify Identity Widget
When Netlify CMS uses the git-gateway backend, it will check for a window.netlifyIdentity object and use that to handle the whole auth flow. This also sets defaults for the git-gateway endpoint, that means it can be used in templates with zero configuration and fit with a one-click deploy to Netlify approach. Netlify Identity itself is based on our open-source GoTrue microservice, and Netlify's Git Gateway project is completely open-source as well. The git-gateway backend will work with Netlify without any setup, but can also be configured to work with any selfhosted GoTrue and Git Gateway instances.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { attempt, isError } from 'lodash';
|
||||
import TestRepoBackend from "./test-repo/implementation";
|
||||
import GitHubBackend from "./github/implementation";
|
||||
import NetlifyAuthBackend from "./netlify-auth/implementation";
|
||||
import GitGatewayBackend from "./git-gateway/implementation";
|
||||
import { resolveFormat } from "../formats/formats";
|
||||
import { selectListMethod, selectEntrySlug, selectEntryPath, selectAllowNewEntries, selectFolderEntryExtension } from "../reducers/collections";
|
||||
import { createEntry } from "../valueObjects/Entry";
|
||||
@ -36,12 +36,12 @@ const slugFormatter = (template = "{{slug}}", entryData) => {
|
||||
const identifier = identifiers.find(ident => ident !== undefined);
|
||||
|
||||
if (identifier === undefined) {
|
||||
throw new Error("Collection must have a field name that is a valid entry identifier");
|
||||
throw new Error("Collection must have a field name that is a valid entry identifier");
|
||||
}
|
||||
|
||||
return identifier;
|
||||
};
|
||||
|
||||
|
||||
return template.replace(/\{\{([^\}]+)\}\}/g, (_, field) => {
|
||||
switch (field) {
|
||||
case "year":
|
||||
@ -88,11 +88,11 @@ class Backend {
|
||||
}
|
||||
|
||||
logout() {
|
||||
if (this.authStore) {
|
||||
this.authStore.logout();
|
||||
} else {
|
||||
throw new Error("User isn't authenticated.");
|
||||
}
|
||||
return Promise.resolve(this.implementation.logout()).then(() => {
|
||||
if (this.authStore) {
|
||||
this.authStore.logout();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getToken = () => this.implementation.getToken();
|
||||
@ -292,8 +292,8 @@ export function resolveBackend(config) {
|
||||
return new Backend(new TestRepoBackend(config), authStore);
|
||||
case "github":
|
||||
return new Backend(new GitHubBackend(config), authStore);
|
||||
case "netlify-auth":
|
||||
return new Backend(new NetlifyAuthBackend(config), authStore);
|
||||
case "git-gateway":
|
||||
return new Backend(new GitGatewayBackend(config), authStore);
|
||||
default:
|
||||
throw new Error(`Backend not found: ${ name }`);
|
||||
}
|
||||
|
Reference in New Issue
Block a user