Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
}
mounted () {
netlifyIdentity.on('init', user => this.login(user))
netlifyIdentity.on('login', user => this.login(user))
netlifyIdentity.on('logout', () => console.log('Logged out'))
netlifyIdentity.on('error', err => console.error('Error', err))
netlifyIdentity.on('open', () => console.log('Widget opened'))
netlifyIdentity.on('close', () => console.log('Widget closed'))
netlifyIdentity.init()
const userx = netlifyIdentity.currentUser()
console.log('hi', userx)
},
mounted() {
const netlifyIdentity = require("netlify-identity-widget");
netlifyIdentity.init()
netlifyIdentity.on('init', this.logIn )
netlifyIdentity.on('login', this.logIn )
netlifyIdentity.on('logout', this.logOut)
const user = this.getUser()
if (user) {
this.logIn(user)
}
this.$router.beforeEach((to, from, next) => {
const user = this.getUser()
if (user) {
this.logIn(user)
} else {
this.logOut(user)
}
next()
})
mounted() {
const netlifyIdentity = require("netlify-identity-widget");
netlifyIdentity.init()
netlifyIdentity.on('init', this.logIn )
netlifyIdentity.on('login', this.logIn )
netlifyIdentity.on('logout', this.logOut)
const user = this.getUser()
if (user) {
this.logIn(user)
}
this.$router.beforeEach((to, from, next) => {
const user = this.getUser()
if (user) {
this.logIn(user)
} else {
this.logOut(user)
}
next()
})
}
logout = callback => {
netlifyIdentity.logout();
netlifyIdentity.on('logout', () => {
this.setState({ user: null });
});
};
return new Promise((resolve, reject) => {
if (isLoggedIn()) {
resolve();
} else {
netlifyIdentity.open();
netlifyIdentity.on('login', user => {
netlifyIdentity.close();
resolve();
});
}
netlifyIdentity.on('error', err => {
reject(err);
});
});
}
const addLoginListener = () =>
netlifyIdentityWidget.on(`login`, () => {
document.location.href = `${__PATH_PREFIX__}/${CMS_PUBLIC_PATH}/`
})
componentDidMount(){
netlifyIdentity.on("login", user => this.updateProducts());
netlifyIdentity.on("logout", () => this.updateProducts());
this.updateProducts();
}
return new Promise((resolve, reject) => {
netlifyIdentity.logout();
netlifyIdentity.on('logout', () => {
resolve();
});
});
}
authenticate = ({ showSignup = false, onSuccess }) => {
netlifyIdentity.open(showSignup && 'signup');
netlifyIdentity.on('login', user => {
this.setState({ user });
onSuccess && onSuccess(user);
});
};