Skip to content

Commit 55dbe28

Browse files
author
sw-yx
committed
example
1 parent b0076ad commit 55dbe28

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
Use [Netlify Identity](https://www.netlify.com/docs/identity/) easier with React! This is a thin wrapper over the [gotrue-js](https://github.com/netlify/gotrue-js) library for easily accessing Netlify Identity functionality in your app, with React Hooks. Types are provided.
88

9-
You can find [a full demo here](https://netlify-gotrue-in-react.netlify.com/) with [source code](https://github.com/netlify/create-react-app-lambda/tree/reachRouterAndGoTrueDemo/src).
9+
Two demos:
10+
11+
- [a full demo here](https://netlify-gotrue-in-react.netlify.com/) with [source code](https://github.com/netlify/create-react-app-lambda/tree/reachRouterAndGoTrueDemo/src)
12+
- the `example` folder here has [a demo hosted here](https://react-netlify-identity.netlify.com) with [deploy logs here](https://app.netlify.com/sites/react-netlify-identity/deploys)
1013

1114
**This library is not officially maintained by Netlify.** This is written by swyx for his own use (and others with like minds 😎) and will be maintained as a personal project unless formally adopted by Netlify. See below for official alternatives.
1215

example/functions/async-dadjoke.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// example of async handler using async-await
22
// https://github.com/netlify/netlify-lambda/issues/43#issuecomment-444618311
33

4-
import fetch from "node-fetch"
5-
export async function handler(event, context) {
4+
const fetch = require("node-fetch")
5+
exports.handler = async function handler(event, context) {
66
try {
77
const response = await fetch("https://icanhazdadjoke.com", { headers: { Accept: "application/json" } })
88
if (!response.ok) {

example/functions/authEndPoint.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
// example of async handler using async-await
22
// https://github.com/netlify/netlify-lambda/issues/43#issuecomment-444618311
33

4-
import fetch from 'node-fetch';
5-
export async function handler(event, context) {
4+
const fetch = require("node-fetch")
5+
exports.handler = async function handler(event, context) {
66
if (!context.clientContext && !context.clientContext.identity) {
77
return {
88
statusCode: 500,
99
body: JSON.stringify({
1010
msg:
11-
'No identity instance detected. Did you enable it? Also, Netlify Identity is not supported on local dev yet.'
11+
"No identity instance detected. Did you enable it? Also, Netlify Identity is not supported on local dev yet."
1212
}) // Could be a custom message or object i.e. JSON.stringify(err)
13-
};
13+
}
1414
}
15-
const { identity, user } = context.clientContext;
15+
const { identity, user } = context.clientContext
1616
try {
17-
const response = await fetch('https://api.chucknorris.io/jokes/random');
17+
const response = await fetch("https://api.chucknorris.io/jokes/random")
1818
if (!response.ok) {
1919
// NOT res.status >= 200 && res.status < 300
20-
return { statusCode: response.status, body: response.statusText };
20+
return { statusCode: response.status, body: response.statusText }
2121
}
22-
const data = await response.json();
22+
const data = await response.json()
2323

2424
return {
2525
statusCode: 200,
2626
body: JSON.stringify({ identity, user, msg: data.value })
27-
};
27+
}
2828
} catch (err) {
29-
console.log(err); // output to netlify function log
29+
console.log(err) // output to netlify function log
3030
return {
3131
statusCode: 500,
3232
body: JSON.stringify({ msg: err.message }) // Could be a custom message or object i.e. JSON.stringify(err)
33-
};
33+
}
3434
}
3535
}

0 commit comments

Comments
 (0)