8.0.0 • Published 8 months ago

@everipedia/iq-login v8.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

🔐 IQ Login

🌟 Introduction

@everipedia/iq-login is a package that provides easy integration of IQ.wiki login functionality into your Next.js applications. It allows users to authenticate using their crypto wallet and web3auth with Wagmi seamlessly.

📦 Installation

pnpm install @everipedia/iq-login wagmi@2.x viem@2.x @web3auth/modal @web3auth/ethereum-provider @web3auth/web3auth-wagmi-connector

🛠️ Setup

  1. Add environment variables:
## .env.local
NEXT_PUBLIC_WEB3_AUTH_CLIENT_ID=your_web3auth_client_id
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=your_wallet_connect_project_id
  1. Add the package to your Tailwind CSS configuration:
// tailwind.config.ts
import type { Config } from "tailwindcss";

const config: Config = {
  content: [
    // ... other content paths
    "./node_modules/@everipedia/iq-login/**/*.{js,jsx,ts,tsx}",
  ],
  // ... rest of your Tailwind config
};

export default config;
  1. Wrap your application with the IqLoginProvider in your layout file:
// app/layout.tsx
import { IqLoginProvider } from "@everipedia/iq-login/client";
import { headers } from "next/headers";
import { getWagmiConfig } from "@everipedia/iq-login";
import { fraxtal } from "viem/chains";

// Get the Wagmi config. It is important that this is outside the component
const wagmiConfig = getWagmiConfig([fraxtal])

export default async function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  const cookie = (await headers()).get("cookie")

  return (
    <html lang="en">
      <body>
        <IqLoginProvider 
          projectName="YOUR_PROJECT_NAME"
          cookie={cookie}
          wagmiConfig={wagmiConfig}
          // Optional props:
          // chains={[mainnet]} // Default: mainnet
          // disableAuth={false} // Default: false
        >
          {children}
        </IqLoginProvider>
      </body>
    </html>
  );
}

You can use any chain supported by viem. Import your desired chain from 'viem/chains' and pass it to the IqLoginProvider:

  1. Add login page to your application:
// app/login/page.tsx
import { Login } from '@everipedia/iq-login';

const LoginPage = () => {
  return (
    <div>
      <Login />
    </div>
  );
};

export default LoginPage;

🔒 Use Auth Hook

// components/my-component.tsx
import { useAuth } from '@everipedia/iq-login';

function MyComponent() {
  const { token, loading, reSignToken, error, logout, web3AuthUser } = useAuth();

  if (loading) return <div>Loading...</div>;
  if (error) return <div>Error: {error}</div>;

  return (
    <div>
      {token ? (
        <>
          <p>Authenticated!</p>
          <button onClick={logout}>Logout</button>
        </>
      ) : (
        <button onClick={reSignToken}>Sign Token</button>
      )}
    </div>
  );
}

🔑 Authentication Helper

import { getAuth } from '@everipedia/iq-login';

const { token, address } = await getAuth();

if (token && address) {
  console.log('User is authenticated');
  console.log('Token:', token);
  console.log('Address:', address);
} else {
  console.log('User is not authenticated');
}

🎨 Styling

The package uses Tailwind CSS and Shadcn UI Theme. Visit https://ui.shadcn.com/themes for theme customization.

📝 Usage on Pages Router

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  transpilePackages: ["@everipedia/iq-login"]
};

export default nextConfig;
5.1.1

1 year ago

5.1.0

1 year ago

6.1.0

1 year ago

6.1.2

1 year ago

6.1.1

1 year ago

6.1.4

12 months ago

6.1.3

1 year ago

7.1.3

10 months ago

7.1.2

10 months ago

7.1.1

10 months ago

7.1.0

10 months ago

7.0.8

12 months ago

7.0.7

12 months ago

7.0.6

12 months ago

7.0.5

12 months ago

7.0.9

12 months ago

5.2.0

1 year ago

6.0.1

1 year ago

6.2.0

12 months ago

7.0.0

12 months ago

7.0.4

12 months ago

7.0.3

12 months ago

7.0.2

12 months ago

7.0.1

12 months ago

7.1.4

10 months ago

8.0.0

8 months ago

7.0.12

12 months ago

7.0.13

12 months ago

7.0.10

12 months ago

7.0.11

12 months ago

5.0.0

1 year ago

4.0.0

1 year ago

3.5.0

1 year ago

3.4.2

1 year ago

3.4.1

1 year ago

3.4.0

1 year ago

3.3.1

1 year ago

3.3.0

1 year ago

3.2.9

1 year ago

3.2.8

1 year ago

3.2.7

1 year ago

3.2.6

1 year ago

3.2.5

1 year ago

3.2.4

1 year ago

3.2.3

1 year ago

3.2.2

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.1.7

1 year ago

3.1.6

1 year ago

3.1.5

1 year ago

3.1.4

1 year ago

3.1.3

1 year ago

3.1.2

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago

3.0.0

1 year ago

2.1.0

1 year ago