Giter Club home page Giter Club logo

gatsby-theme-netlify-identity's Introduction

Gatsby Theme Netlify Identity

This repo is a yarn workspace.

Features:

  • ✅Add Netlify Identity Authentication to any Gatsby app
  • 🕵🏼‍Shadow only the components you need to add authentication to
  • ♿ Accessible modal component that doesn't require a UI redesign unless you want to
  • 💁🏼‍♂️Drop down to use the headless react-netlify-identity API if you want to write your own auth UI

How to Use In Your Gatsby App

⚠️ Make sure to enable Netlify Identity on your site!

this theme adds gatsby-plugin-netlity-identity for you and ships some nice components!

yarn add gatsby-theme-netlify-identity

And add it to your config:

// In your gatsby-config.js
module.exports = {
  plugins: [
    // You can should only have one instance of this plugin
    {
      resolve: `gatsby-theme-netlify-identity`,
      options: {
        url: `https://your-netlify-identity-instance-here.netlify.com/`, // required! Make sure Identity is enabled!
      },
    },
  ],
}

Now you can use IdentityModal and useIdentityContext in your application!

import React from 'react'
import IdentityModal, { useIdentityContext } from 'react-netlify-identity-widget'
import 'react-netlify-identity-widget/styles.css' // delete if you want to bring your own CSS

const Layout = ({ children }) => {
  const identity = useIdentityContext()
  const [dialog, setDialog] = React.useState(false)
  const name =
    (identity &&
      identity.user &&
      identity.user.user_metadata &&
      (identity.user.user_metadata.name || identity.user.user_metadata.full_name)) ||
    'NoName'

  console.log(JSON.stringify(identity))
  const isLoggedIn = identity && identity.isLoggedIn
  return (
    <>
      <nav style={{ background: 'green' }}>
        {' '}
        Login Status:
        <button className="btn" onClick={() => setDialog(true)}>
          {isLoggedIn ? `Hello ${name}, Log out here!` : 'LOG IN'}
        </button>
      </nav>
      <main>{children}</main>
      <IdentityModal showDialog={dialog} onCloseDialog={() => setDialog(false)} />
    </>
  )
}

export default Layout

Tyra

this project also converted https://github.com/madelyneriksen/gatsby-starter-tyra into a theme.

Local Development

yarn workspace demo develop

The demo will start at http://localhost:8000

NOTE: If you’re new to Yarn workspaces, check out this post for details.

gatsby-theme-netlify-identity's People

Contributors

dependabot[bot] avatar swyxio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.