Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(props) {
super(props);
// Initialize NetlifyIdentity
typeof window !== 'undefined' && netlifyIdentity.init();
}
render() {
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/'
})
}
})
if (window.localStorage) {
netlifyIdentity.init()
}
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import Routes from "./Routes";
//node modules
import registerServiceWorker from "./registerServiceWorker";
import { unregister } from "./registerServiceWorker";
import { BrowserRouter as Router } from "react-router-dom";
import netlifyIdentity from "netlify-identity-widget";
netlifyIdentity.init();
ReactDOM.render(
,
document.getElementById("root")
);
// registerServiceWorker();
unregister();
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/'
})
}
})
if (window.localStorage) {
netlifyIdentity.init()
window.netlifyIdentity = netlifyIdentity
}
import React from 'react';
import netlifyIdentity from 'netlify-identity-widget';
netlifyIdentity.init({
// TODO: figure out why this is not working
namePlaceholder: 'Username',
});
export const CurrentUserContext = React.createContext({});
class CurrentUserContextProvider extends React.Component {
state = {
user: netlifyIdentity.currentUser(),
};
authenticate = ({ showSignup = false, onSuccess }) => {
netlifyIdentity.open(showSignup && 'signup');
netlifyIdentity.on('login', user => {
this.setState({ user });
onSuccess && onSuccess(user);
const addLoginListener = () =>
netlifyIdentityWidget.on(`login`, () => {
document.location.href = `${__PATH_PREFIX__}/${CMS_PUBLIC_PATH}/`
})
netlifyIdentityWidget.on(`init`, user => {
if (!user) {
addLoginListener()
} else {
netlifyIdentityWidget.on(`logout`, () => {
addLoginListener()
})
}
})
netlifyIdentityWidget.init()
useEffect(() => {
netlifyIdentity.on("init", handleLogin);
netlifyIdentity.on("login", handleLogin);
netlifyIdentity.on("logout", handleLogout);
netlifyIdentity.init();
}, []);
componentDidMount() {
netlifyIdentity.init()
}