Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: netlify-labs/react-netlify-identity
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.12
Choose a base ref
...
head repository: netlify-labs/react-netlify-identity
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.0.13
Choose a head ref
  • 5 commits
  • 28 files changed
  • 1 contributor

Commits on Apr 24, 2019

  1. readme

    sw-yx committed Apr 24, 2019
    Copy the full SHA
    743a354 View commit details

Commits on Apr 28, 2019

  1. try to deploy

    sw-yx committed Apr 28, 2019
    Copy the full SHA
    4dedb1d View commit details
  2. preflight check

    sw-yx committed Apr 28, 2019
    Copy the full SHA
    42752b5 View commit details
  3. pkgjson

    sw-yx committed Apr 28, 2019
    Copy the full SHA
    2d15208 View commit details
  4. 0.0.13

    sw-yx committed Apr 28, 2019
    Copy the full SHA
    e3eaf98 View commit details
3 changes: 3 additions & 0 deletions .netlify/state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"siteId": "62390d51-d3e5-4901-a676-8ae1a95ea9dc"
}
88 changes: 88 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

## [v0.0.13](https://github.com/sw-yx/react-netlify-identity/compare/v0.0.12...v0.0.13) - 2019-04-28

### Commits

- try to deploy [`4dedb1d`](https://github.com/sw-yx/react-netlify-identity/commit/4dedb1d74115413946cdeda613f29b9c7c76bbb6)
- pkgjson [`2d15208`](https://github.com/sw-yx/react-netlify-identity/commit/2d1520885fdc7c17eeef9587ce01f5964678dbe9)
- readme [`743a354`](https://github.com/sw-yx/react-netlify-identity/commit/743a3548b2a3b0f927b60bb76928b96b4db2c022)

## [v0.0.12](https://github.com/sw-yx/react-netlify-identity/compare/v0.0.11...v0.0.12) - 2019-04-24

### Commits

- actually make it remember [`a8a8106`](https://github.com/sw-yx/react-netlify-identity/commit/a8a8106c9317228848c349487b8626040bc5ebf0)

## [v0.0.11](https://github.com/sw-yx/react-netlify-identity/compare/v0.0.10...v0.0.11) - 2019-04-23

### Commits

- bump dependencies [`cfb29a6`](https://github.com/sw-yx/react-netlify-identity/commit/cfb29a6af608a3bdae412ce43d73fa5a54db7e86)
- remove example, misleading [`2761f6a`](https://github.com/sw-yx/react-netlify-identity/commit/2761f6a931889d1b23fe0ad10e157e8b08c6d2e0)

## [v0.0.10](https://github.com/sw-yx/react-netlify-identity/compare/v0.0.9...v0.0.10) - 2019-04-23

### Commits

- bump gotruejs [`0a88980`](https://github.com/sw-yx/react-netlify-identity/commit/0a88980df1b347565b0f9e772288e66a03e6eea1)

## [v0.0.9](https://github.com/sw-yx/react-netlify-identity/compare/v0.0.8...v0.0.9) - 2019-04-22

### Commits

- proper dependencies [`20fb43a`](https://github.com/sw-yx/react-netlify-identity/commit/20fb43a75dde9e81afef7bf6c008c5ce5fa5c8c3)

## [v0.0.8](https://github.com/sw-yx/react-netlify-identity/compare/v0.0.7...v0.0.8) - 2019-04-22

### Merged

- Add remember option to loginUser [`#2`](https://github.com/sw-yx/react-netlify-identity/pull/2)

### Commits

- Add @svgr/rollup devDependency to package.json [`0ecb730`](https://github.com/sw-yx/react-netlify-identity/commit/0ecb730a6601d477ed6018f99aa8a2b840a6fa1c)
- user [`0a99857`](https://github.com/sw-yx/react-netlify-identity/commit/0a998577cca36567c0d5bf8a280b600b6894d9b8)
- 3rd arg loginuser [`6856fad`](https://github.com/sw-yx/react-netlify-identity/commit/6856fad19c87bb989771a218ac6d061052a335bb)

## [v0.0.7](https://github.com/sw-yx/react-netlify-identity/compare/0.0.7...v0.0.7) - 2019-03-15

### Commits

- pull currentuser on init [`3b593dd`](https://github.com/sw-yx/react-netlify-identity/commit/3b593dded394462ca2679fcfc57baa31d450b2e2)

## [0.0.7](https://github.com/sw-yx/react-netlify-identity/compare/v0.0.5...0.0.7) - 2019-01-10

### Commits

- dont use ref [`dc1c0f0`](https://github.com/sw-yx/react-netlify-identity/commit/dc1c0f093cf07df182444e1e4962bebcfbf2e0e2)
- noproptypes [`72e75ba`](https://github.com/sw-yx/react-netlify-identity/commit/72e75bacdd055fee1ef7b1dcf2440650be13c2e5)

## [v0.0.5](https://github.com/sw-yx/react-netlify-identity/compare/v0.0.3...v0.0.5) - 2019-01-10

### Commits

- update certain things [`561db87`](https://github.com/sw-yx/react-netlify-identity/commit/561db8766f75d130dc64ca3f52e0a313b7dd3119)
- Update README.md [`bc39e80`](https://github.com/sw-yx/react-netlify-identity/commit/bc39e80f587bd6fbeddd9d6e2c52262ef5b2992b)

## [v0.0.3](https://github.com/sw-yx/react-netlify-identity/compare/v0.0.2...v0.0.3) - 2018-12-10

### Commits

- readme [`a20d173`](https://github.com/sw-yx/react-netlify-identity/commit/a20d173ab4a7f00d905ee9a68091913924da1e91)
- update readme [`61124da`](https://github.com/sw-yx/react-netlify-identity/commit/61124da98761c5d765d5ddc1c0ecbbcd957e9c4b)

## v0.0.2 - 2018-12-10

### Commits

- init create-react-library@2.6.7 [`2ae1fc1`](https://github.com/sw-yx/react-netlify-identity/commit/2ae1fc1b5bd3d868a05bbea02c8611699714abf8)
- init [`acdf2e2`](https://github.com/sw-yx/react-netlify-identity/commit/acdf2e29850e6c6a18ac1c33ae3aa373cd878e9e)
- init [`71ba046`](https://github.com/sw-yx/react-netlify-identity/commit/71ba046d3320807cb411dd270973cd9481bd7486)
77 changes: 35 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ yarn add react-netlify-identity
- `isConfirmedUser: boolean`: if they have confirmed their email
- `isLoggedIn: boolean`: if the user is logged in
- `signupUser(email: string, password: string, data: Object)`
- `loginUser(email: string, password: string, remember: Boolean)`
- `loginUser(email: string, password: string, remember: Boolean)` - we default the `remember` term to `true` since you'll usually want to remember the session in localStorage. set it to false if you need to
- `logoutUser()`
- `requestPasswordRecovery(email: string)`
- `recoverAccount(token: string, remember?: boolean | undefined)`
@@ -50,18 +50,14 @@ yarn add react-netlify-identity
- `authedFetch(endpoint: string, obj = {})` (a thin axios-like wrapper over `fetch` that has the user's JWT attached, for convenience pinging Netlify Functions with Netlify Identity)

```tsx
import * as React from 'react';
import * as React from "react"

import { useNetlifyIdentity } from 'react-netlify-identity';
import { useNetlifyIdentity } from "react-netlify-identity"

const IdentityContext = React.createContext(); // not necessary but recommended
const IdentityContext = React.createContext() // not necessary but recommended
function App() {
const identity = useNetlifyIdentity(url); // supply the url of your Netlify site instance. VERY IMPORTANT
return (
<IdentityContext.Provider value={identity}>
{/* rest of your app */}
</IdentityContext.Provider>
);
const identity = useNetlifyIdentity(url) // supply the url of your Netlify site instance. VERY IMPORTANT
return <IdentityContext.Provider value={identity}>{/* rest of your app */}</IdentityContext.Provider>
}
```

@@ -75,32 +71,32 @@ Click for More Example code
```tsx
// log in/sign up example
function Login() {
const { loginUser, signupUser } = React.useContext(IdentityContext);
const formRef = React.useRef();
const [msg, setMsg] = React.useState('');
const { loginUser, signupUser } = React.useContext(IdentityContext)
const formRef = React.useRef()
const [msg, setMsg] = React.useState("")
const signup = () => {
const email = formRef.current.email.value;
const password = formRef.current.password.value;
const email = formRef.current.email.value
const password = formRef.current.password.value
signupUser(email, password)
.then(user => {
console.log('Success! Signed up', user);
navigate('/dashboard');
console.log("Success! Signed up", user)
navigate("/dashboard")
})
.catch(err => console.error(err) || setMsg('Error: ' + err.message));
};
.catch(err => console.error(err) || setMsg("Error: " + err.message))
}
return (
<form
ref={formRef}
onSubmit={e => {
e.preventDefault();
const email = e.target.email.value;
const password = e.target.password.value;
e.preventDefault()
const email = e.target.email.value
const password = e.target.password.value
load(loginUser(email, password, true))
.then(user => {
console.log('Success! Logged in', user);
navigate('/dashboard');
console.log("Success! Logged in", user)
navigate("/dashboard")
})
.catch(err => console.error(err) || setMsg('Error: ' + err.message));
.catch(err => console.error(err) || setMsg("Error: " + err.message))
}}
>
<div>
@@ -121,58 +117,55 @@ function Login() {
{msg && <pre>{msg}</pre>}
</div>
</form>
);
)
}

// log out user
function Logout() {
const { logoutUser } = React.useContext(IdentityContext);
return <button onClick={logoutUser}>You are signed in. Log Out</button>;
const { logoutUser } = React.useContext(IdentityContext)
return <button onClick={logoutUser}>You are signed in. Log Out</button>
}

// check `identity.user` in a protected route
function PrivateRoute(props) {
const identity = React.useContext(IdentityContext);
let { as: Comp, ...rest } = props;
const identity = React.useContext(IdentityContext)
let { as: Comp, ...rest } = props
return identity.user ? (
<Comp {...rest} />
) : (
<div>
<h3>You are trying to view a protected page. Please log in</h3>
<Login />
</div>
);
)
}

// check if user has confirmed their email
// use authedFetch API to make a request to Netlify Function with the user's JWT token,
// letting your function use the `user` object
function Dashboard() {
const { isConfirmedUser, authedFetch } = React.useContext(IdentityContext);
const [msg, setMsg] = React.useState('Click to load something');
const { isConfirmedUser, authedFetch } = React.useContext(IdentityContext)
const [msg, setMsg] = React.useState("Click to load something")
const handler = () => {
authedFetch.get('/.netlify/functions/authEndPoint').then(setMsg);
};
authedFetch.get("/.netlify/functions/authEndPoint").then(setMsg)
}
return (
<div>
<h3>This is a Protected Dashboard!</h3>
{!isConfirmedUser && (
<pre style={{ backgroundColor: 'papayawhip' }}>
You have not confirmed your email. Please confirm it before you ping
the API.
<pre style={{ backgroundColor: "papayawhip" }}>
You have not confirmed your email. Please confirm it before you ping the API.
</pre>
)}
<hr />
<div>
<p>You can try pinging our authenticated API here.</p>
<p>
If you are logged in, you should be able to see a `user` info here.
</p>
<p>If you are logged in, you should be able to see a `user` info here.</p>
<button onClick={handler}>Ping authenticated API</button>
<pre>{JSON.stringify(msg, null, 2)}</pre>
</div>
</div>
);
)
}
```

23 changes: 23 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
13 changes: 13 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Netlify Identity + Reach Router by wrapping the goTrue API in a React Hook.

[Deployed site here](https://unruffled-roentgen-04c3b8.netlify.com/)

this is a demo of using Netlify Identity with Reach Router by wrapping the goTrue API in a React Hook.

⚠️Make sure Netlify Identity is enabled!!! or demo wont work

Reach Router is used to show authentication as per [Ryan Florence](https://twitter.com/ryanflorence/status/1060361144701833216).

If you want to fork/deploy this yourself on Netlfiy, click this:

[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/netlify/create-react-app-lambda/tree/reachRouterAndGoTrueDemo&stack=cms)
25 changes: 25 additions & 0 deletions example/lambda/async-dadjoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// example of async handler using async-await
// https://github.com/netlify/netlify-lambda/issues/43#issuecomment-444618311

import fetch from "node-fetch"
export async function handler(event, context) {
try {
const response = await fetch("https://icanhazdadjoke.com", { headers: { Accept: "application/json" } })
if (!response.ok) {
// NOT res.status >= 200 && res.status < 300
return { statusCode: response.status, body: response.statusText }
}
const data = await response.json()

return {
statusCode: 200,
body: JSON.stringify({ msg: data.joke })
}
} catch (err) {
console.log(err) // output to netlify function log
return {
statusCode: 500,
body: JSON.stringify({ msg: err.message }) // Could be a custom message or object i.e. JSON.stringify(err)
}
}
}
35 changes: 35 additions & 0 deletions example/lambda/authEndPoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// example of async handler using async-await
// https://github.com/netlify/netlify-lambda/issues/43#issuecomment-444618311

import fetch from 'node-fetch';
export async function handler(event, context) {
if (!context.clientContext && !context.clientContext.identity) {
return {
statusCode: 500,
body: JSON.stringify({
msg:
'No identity instance detected. Did you enable it? Also, Netlify Identity is not supported on local dev yet.'
}) // Could be a custom message or object i.e. JSON.stringify(err)
};
}
const { identity, user } = context.clientContext;
try {
const response = await fetch('https://api.chucknorris.io/jokes/random');
if (!response.ok) {
// NOT res.status >= 200 && res.status < 300
return { statusCode: response.status, body: response.statusText };
}
const data = await response.json();

return {
statusCode: 200,
body: JSON.stringify({ identity, user, msg: data.value })
};
} catch (err) {
console.log(err); // output to netlify function log
return {
statusCode: 500,
body: JSON.stringify({ msg: err.message }) // Could be a custom message or object i.e. JSON.stringify(err)
};
}
}
15 changes: 15 additions & 0 deletions example/lambda/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "lambda",
"version": "1.0.0",
"description": "",
"main": "async-dadjoke.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"node-fetch": "^2.4.1"
}
}
8 changes: 8 additions & 0 deletions example/lambda/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


node-fetch@^2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.4.1.tgz#b2e38f1117b8acbedbe0524f041fb3177188255d"
integrity sha512-P9UbpFK87NyqBZzUuDBDz4f6Yiys8xm8j7ACDbi6usvFm6KItklQUKjeoqTrYS/S1k6I8oaOC2YLLDr/gg26Mw==
Loading