Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arcana/auth-react

Package Overview
Dependencies
Maintainers
9
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 for Arcana login handling

  • 0.0.2
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-37.5%
Maintainers
9
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 06 Dec 2022

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