How to use the netlify-identity-widget.currentUser function in netlify-identity-widget

To help you get started, we’ve selected a few netlify-identity-widget examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ejarzo / Shape-Your-Music / src / context / CurrentUserContext / CurrentUserContextProvider.js View on Github external
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);
    });
  };

  logout = callback => {
    netlifyIdentity.logout();
    netlifyIdentity.on('logout', () => {
      this.setState({ user: null });
    });
  };
github danielmahon / gatsby-starter-procyon / src / components / EditableMarkdown.js View on Github external
componentDidMount() {
    const { source, client, node = {} } = this.props;
    const user = netlifyIdentity.currentUser();
    let markdown = source;
    let rawObject = markdownToDraft(markdown);
    // See if we have a locally saved node
    // Saving triggers a server rebuild so we store data locally
    // to account for the delay
    client.query({ query: GET_NODES }).then(({ data: { nodes } }) => {
      const localNode = _.find(nodes, { id: node.id });
      if (localNode) {
        markdown = localNode.content;
        rawObject = markdownToDraft(markdown);
      }
      const editorState = createEditorState(rawObject);
      // If user logged in then show editor
      if (user) {
        this.setState({
          user,
github danielmahon / gatsby-starter-procyon / src / layouts / index.js View on Github external
const authLink = setContext((_, { headers }) => {
  // get the authentication token from local storage if it exists
  const user = netlifyIdentity.currentUser();
  const token = process.env.GATSBY_GRAPHQLCMS_TOKEN;
  // return the headers to the context so httpLink can read them
  return {
    headers: {
      ...headers,
      authorization: user ? `Bearer ${token}` : '',
    },
  };
});
const defaults = {
github uptownhr / hackable / web / pages / index.vue View on Github external
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)



    },
github PrefectHQ / prefect / docs / .vuepress / theme / Layout.vue View on Github external
getUser() {
      const netlifyIdentity = require("netlify-identity-widget")
      if (process.env.PREFECT_DOCS_DEV_MODE === "1"){
        return 1
      } else {
        return netlifyIdentity.currentUser()
      }
    },
    logOut () {
github danielmahon / gatsby-starter-procyon / src / utils / identityActions.js View on Github external
export function loginUser() {
  if (netlifyIdentity && netlifyIdentity.currentUser()) {
    const {
      app_metadata,
      created_at,
      confirmed_at,
      email,
      id,
      user_metadata,
    } = netlifyIdentity.currentUser();

    localStorage.setItem(
      'currentUser',
      JSON.stringify({
        ...app_metadata,
        created_at,
        confirmed_at,
        email,
        id,
        ...user_metadata,
      })
    );
  }
}
github snipcart / gatsby-netlify-serverless / src / pages / index.js View on Github external
getProducts(){
        return netlifyIdentity.currentUser() != null
            ? this.props.data.allMarkdownRemark.edges
            : this.props.data.allMarkdownRemark.edges
                .filter(x => !x.node.frontmatter.private)  
    }
github diegonvs / gatsby-boilerplate / src / services / auth.js View on Github external
export const isLoggedIn = () => {
    return !!netlifyIdentity.currentUser();
}

netlify-identity-widget

Netlify Identity widget for easy integration

MIT
Latest version published 3 years ago

Package Health Score

65 / 100
Full package analysis