diff --git a/README.md b/README.md index f716cf7..d5f3feb 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,12 @@ Three demos: - [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) - [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) - **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. ## Blogposts - [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) - ## List of Alternatives **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 @@ -51,13 +49,19 @@ 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)` - 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 +- `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 - `logoutUser()` - `requestPasswordRecovery(email: string)` -- `recoverAccount(token: string, remember?: boolean | undefined)` - `updateUser(fields: { data: object })` - `getFreshJWT()` -- `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) +- `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 +- `param: TokenParam` + - a token exposing Netlify tokens a dev has to implement the actions for; namely `invite`, `recovery`, `email_change` and `access_denied` + - **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) + - 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 + - for further reference, please check the [type definition](https://github.com/sw-yx/react-netlify-identity/tree/master/src/token.ts) + - an example implementation for a Recovery process can be found below +- `recoverAccount(remember?: boolean)`: verifies and consumes the recovery token caught by `runRoutes`, sets user on success ```tsx import React from 'react'; @@ -89,9 +93,11 @@ function Login() { const { loginUser, signupUser } = useIdentityContext(); const formRef = React.useRef(); const [msg, setMsg] = React.useState(''); + const signup = () => { const email = formRef.current.email.value; const password = formRef.current.password.value; + signupUser(email, password) .then(user => { console.log('Success! Signed up', user); @@ -99,6 +105,7 @@ function Login() { }) .catch(err => console.error(err) || setMsg('Error: ' + err.message)); }; + return (