npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

use-magic-link

v1.1.1

Published

Simple auth setup for your React app in few minutes with [Magic Link](https://magic.link).

Downloads

8

Readme

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.