Socket
Socket
Sign inDemoInstall

@arcana/auth-react

Package Overview
Dependencies
Maintainers
7
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcana/auth-react

Auth component & hooks for Arcana login handling


Version published
Weekly downloads
8
decreased by-82.61%
Maintainers
7
Weekly downloads
 
Created
Source

Auth React

installation

npm install @arcana/auth-react

Usage

Wrap you app with ProvideAuth

index.js

import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import { AuthProvider } from "@arcana/auth";
import { ProvideAuth } from "@arcana/auth-react";

const provider = new AuthProvider(`${appId}`)
const root = ReactDOM.createRoot(document.getElementById("root"));

root.render(
  <React.StrictMode>
    <ProvideAuth provider={provider}>
      <App />
    </ProvideAuth>
  </React.StrictMode>
);

Hooks

useAuth()

App.js

import { useAuth } from "@arcana/auth-react";

function App() {
  const { loading, isLoggedIn, connect, user } = useAuth()

  const onConnectClick = async () => {
    try {
      await connect();
    } catch (err) {
      console.log({ err });
      // Handle error
    }
  };

  if (loading) {
    return <p>Loading...</p>;
  }
  if (!isLoggedIn) {
    return (
      <button onClick={onConnectClick}>
        Connect
      </button>
    );
  }
  return <Info info={user} />;
}

export default App

useAuth return type

type AuthContextType = {
  loading: boolean;
  connect: () => Promise<EthereumProvider>;
  loginWithLink: (p: string) => Promise<EthereumProvider>;
  loginWithSocial: (p: string) => Promise<EthereumProvider>;
  logout: () => void;
  isLoggedIn: boolean;
  availableLogins: Logins[];
  provider: EthereumProvider;
  user: UserInfo | null;
  theme: "dark" | "light";
  logo: string
};

Login component

App.js

import { Auth } from "@arcana/auth-react";

function App() {
  const { isLoggedIn, user } = useAuth()
 
  if (!isLoggedIn) {
    return <Auth theme="light" />;
  }
  return <Info info={user} />;
  
}

export default App;

FAQs

Package last updated on 07 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc