• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple auth setup for your React app in few minutes with Magic Link.

use-magic-link

Simple auth setup for your React app in few minutes with Magic Link.

Read this guide

Install the React Hook

yarn add use-magic-link

Example

Here's how this React hook works:

// Get this with "yarn add use-magic-link"
import useMagicLink from 'use-magic-link'

export default function Home() {
  // create the hook
  const auth = useMagicLink('<Publishable Key>');

  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 (
        <div>
          You are logged-in.
          <br/>
          <button onClick={() => auth.logout()}>Logout</button>
        </div>
      )
    }

    // Show this, if not logged-in
    return (
      <div>
        <button onClick={loginNow}>Login Now</button>
      </div>
    )
  }

  return (
    <div className="container">
      <main>
        <h1>Next.js Bank</h1>
        <div className="content">{getContent()}</div>
      </main>
    </div>
  )
}

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('<Publishable Key>')

You can get the <Publishable Key> by logging into the Magic Link dashboard.

Here are the properties of auth:

auth.loading

It will be true, until we load additional libraries and check the current login state.

auth.loggedIn

It will be true, if we are loggedIn, otherwise false.

auth.loggingIn

It will be true, once we start the login process.

auth.loggingOut

It will be true, once we start the logout process.

auth.error

Store the error object, if something goes wrong.

auth.login(email)

You can start the login process by passing a valid email.

auth.logout()

You can start the logout process.

auth.fetch

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

auth.magic

The underline Magic Link API client. Read Magic Link documentation on how to use it.

More Repositories

1

meteor-up-legacy

Production Quality Meteor Deployments
JavaScript
2,268
star
2

react-komposer

Feed data into React components by composing containers.
JavaScript
735
star
3

node-usage

process usage lookup with nodejs
JavaScript
390
star
4

meteor-streams

Realtime messaging for Meteor
JavaScript
286
star
5

laika

testing framework for meteor
JavaScript
242
star
6

meteor-ddp-analyzer

Simple DDP Proxy which logs DDP messages
JavaScript
151
star
7

meteor-smart-collections

Meteor Collections Re-Imagined
JavaScript
148
star
8

meteor-cluster

Smarter way to run cluster of meteor nodes
JavaScript
100
star
9

learnnextjs-demo

Demo App of the http://learnnextjs.com
JavaScript
94
star
10

nodemiral

Server Automation for NodeJS over SSH
JavaScript
93
star
11

nariya

Continuous Deployment Server
JavaScript
67
star
12

hello-react-meteor

Learning Some React with Proper Meteor Integration (Routing, SSR)
JavaScript
65
star
13

meteor-static-blog

Static Blog Made with Meteor
JavaScript
60
star
14

chrome-node

NodeJS Runtime for Chrome (For Packaged Apps)
55
star
15

mongo-metrics

Metrics tracking and aggregation with MongoDB
JavaScript
54
star
16

node-redis-scripto

Redis Script Manager for NodeJS
JavaScript
52
star
17

travis-ci-meteor-packages

Travis CI support for Meteor (Smart) Packages
JavaScript
52
star
18

open-comment-box

OpenSource Realtime Comments Platforms
JavaScript
49
star
19

horaa

Mocking NodeJS Modules
JavaScript
45
star
20

fastai-shell

A workflow to setup and use fastai on Google Cloud Platfrom
Shell
42
star
21

streams-blackboard

Realtime Blackboard with Meteor Streams
JavaScript
38
star
22

podda

Simple Reactive DataStore for JavaScript
JavaScript
33
star
23

meteor-find-faster

Faster & Efficient Implementation of Meteor's Collection.find()
JavaScript
33
star
24

meteor-streams-chat-app

Chat App with Meteor Streams
JavaScript
31
star
25

coursebook-server

JavaScript
27
star
26

coursebook-ui

Main UI for coursebook
JavaScript
26
star
27

keep-calm-and-node-on

KEEP CALM and NODE ON
23
star
28

drev

DREV - Distributed Redis based EventEmitter for NodeJS
JavaScript
21
star
29

meteor-custom-authentication-system

Custom Authentication System for Meteor
JavaScript
21
star
30

dcoinwallet

"A Bitcoin Wallet" for power users.
JavaScript
20
star
31

meteor-seo-without-spiderable

Meteor SEO support without spiderable
JavaScript
20
star
32

nextjs-e2e-demo

Next.js E2E Demo
JavaScript
19
star
33

nextjs-magic-bank

JavaScript
18
star
34

mocha-mongo

Set of mongodb testing helpers for mocha
JavaScript
18
star
35

reaktor-demo

Demo of Reaktor - New Router Syntax for FlowRouter + ReactLayout
JavaScript
18
star
36

meteor-apm-client

Application Performance Monitoring for Meteor
JavaScript
17
star
37

meteor-ssr-demo-page-rendering

Rendering Pages on the Server via meteor-ssr
JavaScript
17
star
38

bulletproof-next-app

JavaScript
15
star
39

nextjs-issg-example

A simple example featuring Next.js iSSG
JavaScript
15
star
40

jailguard

Safe Way to Run User Provided JavaScript with NodeJS
JavaScript
15
star
41

arunoda.me

My personal website + blog
JavaScript
13
star
42

hello-laika

Sample app with tests written in laika
JavaScript
11
star
43

heroku-nodejs-binary-buildback

Official NodeJS Binaries on Heroku
Shell
11
star
44

stress-test-meteor

Stress Test Meteor
JavaScript
11
star
45

pick-mongo-primary

Get MongoDB Shell command to PRIMARY from the Mongo URL
JavaScript
10
star
46

adeep

Jupyter Notebook
9
star
47

cmake-boilerplate

CMake Boilerplate for C
C
9
star
48

qbox

Quick Flow controller for NodeJS
JavaScript
9
star
49

rn-storybook

React Native storybook demo
Objective-C
9
star
50

travis-ci-laika

Travis CI support for laika
Shell
8
star
51

wait-for-mongo

Simple utility which waits until mongodb to come online
JavaScript
8
star
52

try-apollo

My first proper attempt with Apollo
JavaScript
8
star
53

learn-redux

JavaScript
7
star
54

next-apollo-demo

Simple Next.js example with Apollo
JavaScript
7
star
55

jquery-signature

Getting a unique signature for a dom event using jQuery
JavaScript
7
star
56

node-userdown

Run node apps with stepping down user permissions
JavaScript
7
star
57

awesome-blackboard

JavaScript
7
star
58

coursebook-publish

Publish lessons into coursebook
JavaScript
7
star
59

appzone-ussd-sim

Rich USSD Simulator for Appzone
JavaScript
7
star
60

Appzone-NodeJS

NodeJS Client for Appzone
JavaScript
6
star
61

marlin

Marlin firmware for My Tevo Tornado
C
6
star
62

nextjs-example-preload-data

A Next.js example with data preloading
JavaScript
6
star
63

winstoon

A Simple Wrapper for Winston
JavaScript
6
star
64

meteor-subscription-manager

Subscription Manager for Meteor
JavaScript
6
star
65

cas-pipes

MongoDB Aggregation Pipelines meets Cassandra
JavaScript
5
star
66

kgatsby

Gatsby starter for a Contentful project.
JavaScript
5
star
67

AppZone-Community-Simulator

Simulator for AppZone.lk powered by the Community
JavaScript
5
star
68

meteor-heapsave

Take Heapdumps and save them into S3
JavaScript
5
star
69

mnode

How to find the node version used by Meteor
JavaScript
5
star
70

meteor-runner

Best way to run meteor apps in production
JavaScript
4
star
71

meteor-version-playground

Play with Meteor 0.9 Package Versions
JavaScript
4
star
72

tusker

Redis Based Distributed Task Locking
JavaScript
4
star
73

lesson-nextjs-static-regeneration

JavaScript
3
star
74

telescope-client

Telescope Client Hosted on Heroku
3
star
75

datocms-hugo-portfolio-demo-4731

CSS
3
star
76

very-bad-app

Very bad app which scores 100% on lightshouse
JavaScript
3
star
77

github-cms-demo-data

Data for the Next.js blog using GitHub CMS
3
star
78

github-issue-search

Github Issue Search Meteor App
JavaScript
3
star
79

cryptocurrency

Playing with https://www.coursera.org/learn/cryptocurrency
JavaScript
3
star
80

hello-laika-discover-meteor

Laika Hello World example for the Discover Meteor Screencast
JavaScript
3
star
81

react-kode-camp-todo

A todo app used for React Kode Camp
JavaScript
2
star
82

Appzone-CMD

Command line utility for Appzone.lk platform
2
star
83

meteor-user-authorization-test-with-laika

Meteor user authorization testing with meteor
JavaScript
2
star
84

youfool.art

The Simplest NFT Platform Ever
JavaScript
2
star
85

nariya-helloworld

Nariya Helloworld App
JavaScript
2
star
86

multiuser-sms-simulator

Multiuser SMS Simulator
JavaScript
2
star
87

datocms-snipcart-gatsby-example-demo-6375

CSS
2
star
88

AppZoneSimulator

Rich Simulator for AppZone.lk
JavaScript
2
star
89

fast-render-telescope

Telescope with Fast Render (using for fast-render QA)
JavaScript
2
star
90

hibar

Intelligent JQuery
JavaScript
2
star
91

mongotest

Helper functions for testing with mongodb
JavaScript
2
star
92

meteor-rethink-hello

meteor-rethink-hello
JavaScript
2
star
93

gc-game

JavaScript
2
star
94

fashona-learnbox

Fashona LearnBox
JavaScript
2
star
95

appzone-live-test

Live Test Appzone Applications
JavaScript
2
star
96

wantrepreneur-realised

I was a Wantrepreneur, but I realised!
2
star
97

AppZone-Java-Sample

Java Maven Sample for AppZone.lk
Java
2
star
98

nodespy

Spy and Expectation Framework for NodeJS with Stubbing
JavaScript
2
star
99

AppZone-Java-Client

OpenSource Java Client for AppZone.lk
Java
2
star
100

fastai-courses

Holds notebooks related to fastai courses I'm working on
Jupyter Notebook
2
star