├── index.js ├── .gitignore ├── gatsby-ssr.js ├── gatsby-browser.js ├── package.json ├── CHANGELOG.md ├── LICENSE └── README.md /index.js: -------------------------------------------------------------------------------- 1 | //noop 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /gatsby-ssr.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { IdentityContextProvider } from 'react-netlify-identity-widget' 3 | export const wrapRootElement = ({ element }, { url }) => 4 | React.createElement( 5 | IdentityContextProvider, 6 | { 7 | url: url, 8 | }, 9 | element, 10 | ) 11 | -------------------------------------------------------------------------------- /gatsby-browser.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { IdentityContextProvider } from 'react-netlify-identity-widget' 3 | export const wrapRootElement = ({ element }, { url }) => 4 | React.createElement( 5 | IdentityContextProvider, 6 | { 7 | url: url, 8 | }, 9 | element, 10 | ) 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gatsby-plugin-netlify-identity", 3 | "description": "Gatsby plugin which adds a React Netlify Identity Widget Provider for you", 4 | "version": "0.0.3", 5 | "main": "index.js", 6 | "repository": "https://github.com/sw-yx/gatsby-plugin-netlify-identity.git", 7 | "homepage": "https://github.com/sw-yx/gatsby-plugin-netlify-identity", 8 | "author": "sw-yx ", 9 | "license": "MIT", 10 | "dependencies": { 11 | "react-netlify-identity-widget": "^0.1.3" 12 | }, 13 | "keywords": [ 14 | "gatsby", 15 | "gatsby-plugin", 16 | "netlify", 17 | "netlify-identity" 18 | ], 19 | "peerDependencies": { 20 | "gatsby": "^2.0.0" 21 | }, 22 | "scripts": { 23 | "version": "auto-changelog -p --template keepachangelog && git add .", 24 | "prepublishOnly": "git push && git push --tags && gh-release" 25 | }, 26 | "devDependencies": { 27 | "auto-changelog": "^1.13.0", 28 | "gh-release": "^3.5.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 7 | 8 | Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). 9 | 10 | ## [v0.0.3](https://github.com/sw-yx/gatsby-plugin-netlify-identity/compare/v0.0.2...v0.0.3) - 2019-07-31 11 | 12 | ### Commits 13 | 14 | - transpile [`98cf123`](https://github.com/sw-yx/gatsby-plugin-netlify-identity/commit/98cf123627480f1e50c3a4d8f906495c78601a5a) 15 | 16 | ## v0.0.2 - 2019-06-10 17 | 18 | ### Commits 19 | 20 | - init [`a93c18c`](https://github.com/sw-yx/gatsby-plugin-netlify-identity/commit/a93c18cbcc29d4be22cea34b799622846963daee) 21 | - add devdeps [`7ac4bff`](https://github.com/sw-yx/gatsby-plugin-netlify-identity/commit/7ac4bffbb185b628162df772368b6efc72e54946) 22 | - Initial commit [`afba7a4`](https://github.com/sw-yx/gatsby-plugin-netlify-identity/commit/afba7a4d405780742f3cf45c306baed77c81c20b) 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 swyx 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gatsby-plugin-netlify-identity 2 | 3 | Gatsby plugin which adds a React Netlify Identity Widget Provider for you! 4 | 5 | This is a very light wrapper just to help automate the boring parts, please see https://github.com/sw-yx/react-netlify-identity-widget for more info on how to use RNIW. 6 | 7 | ## Install 8 | 9 | ```bash 10 | npm install --save gatsby-plugin-netlify-identity 11 | ## you may also need RNIW's peer dependencies 12 | npm install --save react-netlify-identity-widget @reach/dialog @reach/tabs @reach/visually-hidden 13 | ``` 14 | 15 | ## How to use 16 | 17 | ```javascript 18 | // In your gatsby-config.js 19 | module.exports = { 20 | plugins: [ 21 | // You can should only have one instance of this plugin 22 | { 23 | resolve: `gatsby-plugin-netlify-identity`, 24 | options: { 25 | url: `https://your-identity-instance-here.netlify.com/` // required! 26 | } 27 | } 28 | ] 29 | } 30 | ``` 31 | 32 | ## Options 33 | 34 | To use this, you must have a Netlify site instance with Netlify Identity enabled ([Deploy this demo to get started with one click](https://app.netlify.com/start/deploy?repository=https://github.com/sw-yx/jamstack-hackathon-starter&stack=cms&utm_source=github&utm_medium=swyx-RNI&utm_campaign=devex)). Then take the URL of that Netlify site and pass it in as the `url` for this plugin's options. 35 | 36 | ## Usage 37 | 38 | Once installed, you are free to use `react-netlify-identity-widget`'s handy `useIdentityContext` hook anywhere in your Gatsby app. If you also want the authentication modal, you can import it as well. A good place to put this is in a Layout component, but really you could also put it in a Navbar component, it really doesn't matter since you're inside the context anyway. 39 | 40 | Some sample code for your convenience: 41 | 42 | ```js 43 | // src/components/Layout.js 44 | import React from "react" 45 | import IdentityModal, { useIdentityContext } from "react-netlify-identity-widget" 46 | import "react-netlify-identity-widget/styles.css" // delete if you want to bring your own CSS 47 | 48 | const Layout = ({ children }) => { 49 | const identity = useIdentityContext() // see https://github.com/sw-yx/react-netlify-identity for api of this identity object 50 | const [dialog, setDialog] = React.useState(false) 51 | const name = 52 | (identity && identity.user && identity.user.user_metadata && identity.user.user_metadata.name) || "NoName" 53 | 54 | console.log(JSON.stringify(identity)) 55 | const isLoggedIn = identity && identity.isLoggedIn 56 | return ( 57 | <> 58 | 65 |
{children}
66 | setDialog(false)} /> 67 | 68 | ) 69 | } 70 | 71 | export default Layout 72 | ``` 73 | 74 | A very simple and unmaintained demo is here: https://github.com/sw-yx/plsdelete-netlify-identity-loop-bug 75 | --------------------------------------------------------------------------------