Coder Social home page Coder Social logo

worldspaceinc / magic-link Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thirdweb-example/magic-link

0.0 0.0 0.0 267 KB

Connect users to your dApp using just their email using thirdweb's useMagic hook!

Home Page: https://magic-link.thirdweb-example.com

License: Apache License 2.0

Shell 0.37% JavaScript 1.29% TypeScript 60.16% CSS 38.18%

magic-link's Introduction

Magic Link Wallet Connection

This project demonstrates how to use Magic Link with thirdweb using the useMagic hook from the thirdweb React SDK.

Magic Link enables users to connect to your dApp using email, phone number, or social login.

Check out the Demo here: https://magic-link.thirdweb-example.com

Tools:

  • thirdweb React SDK: We're using the useAddress, useMagic, and useDisconnect hooks from our React SDK to enable users to connect/disconnect to your dApp via their wallets, and to show information about their connected wallet.
  • thirdweb TypeScript SDK: We're using the ThirdwebProvider to configure the Network we want our user's to be on, and to configure the Magic Link Wallet Connector with our API key.
  • Magic Link: Under the hood, thirdweb's useMagic hook uses the Magic Link Web SDK to connect user's wallets to their email, phone number, or social media accounts.
  • Next.JS: Next.JS isn't really necessary for this project, but it's nice to have if you want to build more advanced features in the future.

Using This Repo

  • Create an account at https://magic.link/

  • Copy your Publishable API Key from the Magic Link dashboard.

  • Create a .env.local file at the root of your project, and add your key in the format: NEXT_PUBLIC_MAGIC_LINK_API_KEY=xxx, like as it is in .env.example.

  • Clone this example project by running:

npx thirdweb create --template magic-link

Guide

Setting Up Magic Link WalletConnector

Over in _app.tsx we are wrapping our application with the ThirdwebProvider component, which allows us to configure the Network we want our user's to be on, and to configure the Magic Link Wallet Connector with our API key.

<ThirdwebProvider desiredChainId={activeChainId} walletConnectors={connectors}>
  <Component {...pageProps} />
</ThirdwebProvider>

Configuring the Network

const activeChainId = ChainId.Mumbai;

Configuring the Magic Link Wallet Connector

const magicLinkWalletConnector: WalletConnector = {
  name: "magic",
  options: {
    // Replace this with your own magic link api key
    apiKey: process.env.NEXT_PUBLIC_MAGIC_LINK_API_KEY as string,
    rpcUrls: {
      [ChainId.Mumbai]: "https://mumbai.magic.io/rpc",
    },
  },
};

Logging Users In Via Email

On the Home Page, we are using the useMagic hook to connect user's wallets' by submitting their email address.

Once the user enters their email and clicks the Login button, they will be connected to their wallet via a Magic Link (email with a link is sent to the user's email - they are signed in after they click this link).

const connectWithMagic = useMagic();

// ...

<a onClick={() => connectWithMagic({ email })}>Login</a>;

Once they're connected, we grab their address using the useAddress hook and hide the form!

const address = useAddress();

If the user wants to disconnect at any time, we allow them to, using the useDisconnect hook.

const disconnectWallet = useDisconnect();

Join our Discord!

For any questions, suggestions, join our discord at https://discord.gg/thirdweb.

magic-link's People

Contributors

jarrodwatts avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.