Simple auth setup for your React app in few minutes with [Magic Link](https://magic.link).
npm install use-magic-linkSimple auth setup for your React app in few minutes with Magic Link.
```
yarn add use-magic-link
Here's how this React hook works:
`js
// Get this with "yarn add use-magic-link"
import useMagicLink from 'use-magic-link'
export default function Home() {
// create the hook
const auth = useMagicLink('
function loginNow() {
const email = prompt('Enter your email');
auth.login(email);
}
function getContent() {
// Show a loading screen until we detect the login-state
if (auth.loading || auth.loggingIn || auth.loggingOut) {
return '...'
}
// Show this, if logged in
if (auth.loggedIn) {
return (
// Show this, if not logged-in
return (
return (
API
You will get an auth object after you call the
use-magic-link React hook. > Make sure to call this inside a functional component or inside another React hook.
`
import useMagicLink from 'use-magic-link'// inside a functional component
const auth = useMagicLink('')
`> You can get the
by logging into the Magic Link dashboard.Here are the properties of
auth:$3
It will be
true, until we load additional libraries and check the current login state.$3
It will be
true, if we are loggedIn, otherwise false.$3
It will be
true, once we start the login process.$3
It will be
true, once we start the logout process.$3
Store the error object, if something goes wrong.
$3
You can start the login process by passing a valid email.
$3
You can start the logout process.
$3
An instance of
fetch, which automatically includes the Magic Link token. You can use this to call any API which uses @magic-sdk/admin` NPM module to authenticate the request.Read this guide for more information
The underline Magic Link API client. Read Magic Link documentation on how to use it.