Quickstart

Get "Sign in with NetworkCoin" working in 5 minutes.

Prerequisites: A NETWORKCOIN.ID account and an app registered in the Console with your redirect URI configured.

1. Install the SDK

Terminal
npm install @networkcoin/sdk

2. Add the Provider

Wrap your app with NetworkCoinProvider. This sets up the OAuth client and handles callbacks automatically.

app/providers.tsx
import { NetworkCoinProvider } from '@networkcoin/sdk/react';

export function Providers({ children }) {
  return (
    <NetworkCoinProvider
      clientId="your-client-id"
      redirectUri="http://localhost:3000/callback"
      scope="openid profile email wallet"
    >
      {children}
    </NetworkCoinProvider>
  );
}

3. Use the Hook

Call useNetworkCoin() in any component to access auth state and methods.

app/page.tsx
'use client';
import { useNetworkCoin } from '@networkcoin/sdk/react';

export default function Home() {
  const { user, isAuthenticated, isLoading, login, logout } = useNetworkCoin();

  if (isLoading) return <p>Loading...</p>;

  if (!isAuthenticated) {
    return <button onClick={login}>Sign in with NetworkCoin</button>;
  }

  return (
    <div>
      <h1>Welcome, {user?.name}!</h1>
      <p>Email: {user?.email}</p>
      <p>Wallet: {user?.wallet_address}</p>
      <button onClick={() => logout('http://localhost:3000')}>Sign out</button>
    </div>
  );
}

That's it. The SDK handles PKCE, state verification, token exchange, auto-refresh, and logout for you.

Alternative: NextAuth.js

If you're already using NextAuth/Auth.js, add NETWORKCOIN.ID as an OIDC provider:

auth.ts
import NextAuth from 'next-auth';

export const { handlers, auth } = NextAuth({
  providers: [{
    id: 'networkcoin',
    name: 'NetworkCoin ID',
    type: 'oidc',
    issuer: 'https://id.networkcoin.ai',
    clientId: process.env.NETWORKCOIN_CLIENT_ID,
    clientSecret: process.env.NETWORKCOIN_CLIENT_SECRET,
  }],
});

Alternative: Manual OAuth Flow

For non-React apps, use any OAuth2/OIDC library and point it at our discovery endpoint:

Issuer:          https://id.networkcoin.ai
Discovery:       https://id.networkcoin.ai/.well-known/openid-configuration
Authorization:   https://id.networkcoin.ai/oauth/authorize
Token:           https://id.networkcoin.ai/oauth/token
UserInfo:        https://id.networkcoin.ai/oauth/userinfo
JWKS:            https://id.networkcoin.ai/.well-known/jwks.json

See the Authentication Flow guide for the full manual implementation.