You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+87-7
Original file line number
Diff line number
Diff line change
@@ -12,14 +12,12 @@ Three demos:
12
12
-[example with Reach Router](https://github.com/sw-yx/react-netlify-identity/tree/master/examples/example-reach-router) with [a demo hosted here](https://react-netlify-identity.netlify.com) and [deployed logs here](https://app.netlify.com/sites/react-netlify-identity/deploys)
13
13
-[example with React Router](https://github.com/sw-yx/react-netlify-identity/tree/master/examples/example-react-router) with [a demo hosted here](https://react-netlify-identity-example.netlify.com)
14
14
15
-
16
15
**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.
17
16
18
17
## Blogposts
19
18
20
19
-[Add Netlify Identity Authentication to any React App in 5 minutes with React Context, Hooks and Suspense](https://dev.to/swyx/add-netlify-identity-authentication-to-any-react-app-in-5-minutes-with-react-context-hooks-and-suspense-5gci)
21
20
22
-
23
21
## List of Alternatives
24
22
25
23
**Lowest level JS Library**: If you want to use the official Javascript bindings to GoTrue, Netlify's underlying Identity service written in Go, use https://github.com/netlify/gotrue-js
-`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
52
+
-`loginUser(email: string, password: string, remember: boolean = true)` - 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
-`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)
57
+
-`authedFetch(endpoint: string, obj: RequestInit = {})` a thin axios-like wrapper over `fetch` that has the user's JWT attached, for convenience pinging Netlify Functions with Netlify Identity
58
+
-`param: TokenParam`
59
+
- a token exposing Netlify tokens a dev has to implement the actions for; namely `invite`, `recovery`, `email_change` and `access_denied`
60
+
-**Important:** tokens this package exposes no methods for are automatically handled and will not be passed down - see [runRoutes implementation](https://github.com/sw-yx/react-netlify-identity/master/src/runRoutes.tsx)
61
+
- if you don't want this behaviour (added [here](https://github.com/sw-yx/react-netlify-identity/issues/12) in v.0.1.8), pass `runRoutes={false}` to the exposed hook
62
+
- for further reference, please check the [type definition](https://github.com/sw-yx/react-netlify-identity/tree/master/src/token.ts)
63
+
- an example implementation for a Recovery process can be found below
64
+
-`recoverAccount(remember?: boolean)`: verifies and consumes the recovery token caught by `runRoutes`, sets user on success
// important to check for the current pathname here because else you land
253
+
// in a infinite loop
254
+
if (token&&type==='recovery'&&pathname==='/') {
255
+
replace(`/recovery`, { token });
256
+
}
257
+
258
+
returnnull;
259
+
}
260
+
261
+
function RecoveryPage() {
262
+
const {
263
+
location: { state },
264
+
} =useHistory();
265
+
// this state _might_ not be needed, it was needed in my specific implementation
266
+
const [token] =useState(state?.token);
267
+
268
+
returnnull; // set new password in a form and call updateUser
269
+
}
270
+
```
271
+
272
+
</details>
273
+
192
274
## Lower level API: `useNetlifyIdentity`
193
275
194
276
If you'd like to handle your own context yourself, you can use this library as a hook as well:
@@ -201,8 +283,6 @@ function useNetlifyIdentity(
201
283
):ReactNetlifyIdentityAPI;
202
284
```
203
285
204
-
the library watches for and handles confirmation routes by default. If you don't like this, pass `enableRunRoutes: false`. This was added here https://github.com/sw-yx/react-netlify-identity/issues/12 in v0.1.8
0 commit comments