Improve netlifyIdentity process
This commit is contained in:
parent
ff7dc18f4a
commit
7a6d9dd223
5 changed files with 27 additions and 2 deletions
|
|
@ -27,6 +27,7 @@
|
|||
"yamljs": "^0.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"netlify-identity-widget": "^1.2.0",
|
||||
"polished": "^1.2.1",
|
||||
"react": "^16.0.0",
|
||||
"react-dom": "^16.0.0",
|
||||
|
|
|
|||
|
|
@ -6,12 +6,19 @@
|
|||
<title>Content Manager</title>
|
||||
|
||||
<!-- Include the styles for the Netlify CMS UI, after your own styles -->
|
||||
<link rel="stylesheet" href="https://unpkg.com/netlify-cms@0.5.0/dist/cms.css" />
|
||||
<link rel="stylesheet" href="https://unpkg.com/netlify-cms/dist/cms.css" />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<!-- Include the script that builds the page and powers Netlify CMS -->
|
||||
<script src="https://unpkg.com/netlify-cms@0.5.0/dist/cms.js"></script>
|
||||
<script src="https://identity-js.netlify.com/v1/netlify-identity-widget.js"></script>
|
||||
<script src="https://unpkg.com/netlify-cms/dist/cms.js"></script>
|
||||
|
||||
<script>
|
||||
// redirect when logging out
|
||||
window.netlifyIdentity.on('logout', function () {
|
||||
document.location.href = '/'
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import React from 'react'
|
|||
import { render } from 'react-snapshot'
|
||||
import App from './App'
|
||||
import registerServiceWorker from './registerServiceWorker'
|
||||
import './netlifyIdentity'
|
||||
|
||||
const rootEl = document.getElementById('root')
|
||||
render(<App />, rootEl)
|
||||
|
|
|
|||
12
src/netlifyIdentity.js
Normal file
12
src/netlifyIdentity.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import netlifyIdentity from 'netlify-identity-widget'
|
||||
|
||||
// check for netlifyIdentity, redirect to admin if user is logging in
|
||||
netlifyIdentity.on('init', user => {
|
||||
if (!user) {
|
||||
netlifyIdentity.on('login', () => {
|
||||
document.location.href = '/admin/'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
netlifyIdentity.init()
|
||||
|
|
@ -4956,6 +4956,10 @@ negotiator@0.6.1:
|
|||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9"
|
||||
|
||||
netlify-identity-widget@^1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/netlify-identity-widget/-/netlify-identity-widget-1.2.0.tgz#c3cb2498b3550fae4deb133de17ff6a3b2cb6ebf"
|
||||
|
||||
no-case@^2.2.0:
|
||||
version "2.3.1"
|
||||
resolved "https://registry.yarnpkg.com/no-case/-/no-case-2.3.1.tgz#7aeba1c73a52184265554b7dc03baf720df80081"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue