mirror of
https://github.com/kingomarnajjar/gatsby-starter-netlify-cms.git
synced 2026-07-25 22:27:24 +10:00
redirect user to cms
This commit is contained in:
parent
22a2d76847
commit
6897e6a97c
3 changed files with 47 additions and 12 deletions
47
src/html.js
Normal file
47
src/html.js
Normal 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>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue