redirect user to cms

This commit is contained in:
Austin Green 2017-10-27 20:52:40 -04:00
parent 22a2d76847
commit 6897e6a97c
3 changed files with 47 additions and 12 deletions

47
src/html.js Normal file
View file

@ -0,0 +1,47 @@
import React from 'react';
let stylesStr;
if (process.env.NODE_ENV === `production`) {
try {
stylesStr = require(`!raw-loader!../public/styles.css`);
} catch (e) {
console.log(e);
}
}
module.exports = class HTML extends React.Component {
render() {
let css;
if (process.env.NODE_ENV === `production`) {
css = <style id="gatsby-inlined-css" dangerouslySetInnerHTML={{ __html: stylesStr }} />;
}
return (
<html {...this.props.htmlAttributes}>
<head>
<meta charSet="utf-8" />
<meta httpEquiv="x-ua-compatible" content="ie=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
{this.props.headComponents}
{css}
<script src="https://identity.netlify.com/v1/netlify-identity-widget.js" />
</head>
<body {...this.props.bodyAttributes}>
{this.props.preBodyComponents}
<div key={`body`} id="___gatsby" dangerouslySetInnerHTML={{ __html: this.props.body }} />
{this.props.postBodyComponents}
<script>
if (window.netlifyIdentity) {
window.netlifyIdentity.on('init', user => {
if (!user) {
window.netlifyIdentity.on('login', () => {
document.location.href = '/admin/';
});
}
});
}
</script>
</body>
</html>
);
}
};

View file

@ -1,6 +1,5 @@
import React from 'react';
import Link from 'gatsby-link';
import Helmet from 'react-helmet';
export default function Index({ data }) {
const { edges: posts } = data.allMarkdownRemark;

View file

@ -10,16 +10,5 @@
</head>
<body>
<script src="https://unpkg.com/netlify-cms@^0.5.0/dist/cms.js"></script>
<script>
if (window.netlifyIdentity) {
window.netlifyIdentity.on('init', user => {
if (!user) {
window.netlifyIdentity.on('login', () => {
document.location.href = '/admin/';
});
}
});
}
</script>
</body>
</html>