KUB Docs
  • Introduction to KUB
  • Connect to KUB
  • KUB PoS
    • Increase block gas limit to 90M
    • Update GasPrice Instruction
    • Incident from chaophaya hardfork
    • Overview
    • Considerations
    • Validator Node
      • Node Requirements
      • Run Validator Node
      • Validator Staking
      • StakeManager Contract
      • ValidatorShare Contract
      • Slashing
    • Run Full Node
    • Run Archive Node
    • Chaindata Snapshot
    • Migration PoSA to PoS
    • Delegator
      • How to delegate
      • How to claim reward
      • How to unstake
  • Developer Center
    • ✨Getting Started
    • 🏆Project Tiers
    • 👨‍💻Connect Bitkub NEXT to register as a new user
    • ✔️Verify your identity via Bitkub NEXT (KYC or KYB)
    • 💰Subscribe to the KUB Developer Package
    • 🗳️Submit your project
      • 📗Create submit project
      • 📘Manage your project
        • Submit project
        • Create a new project version
        • Status of project version
      • 📙Manage project information
  • KUB SDK
    • NEXT SDK
      • NEXT SDK Code Cookbook
      • KUB SDK Compatible Smart Contract
        • Example Smart Contract for Testing
        • Example KUB SDK Compatible KAP20 Smart Contract
        • Example KUB SDK Compatible KAP721 Smart Contract
  • KUB Playground
    • Quick Start Guide on KUB Playground
  • KUB Layer 2
  • KUB Scan
  • RPC Service
    • JSON-RPC Endpoint
  • IPFS Service
    • IPFS Guideline
  • FAQ
  • Glossary
  • Reference and Service
    • KUB Whitepaper Version 3.3
    • Technical Paper Version 3.2
    • KUB Explorer
    • KUB Faucet
    • KUB Oracle
    • KUB Bridge
    • KKUB OTP
Powered by GitBook
On this page
  • Overview step
  • 1. Configuration
  • 2. Usage

Was this helpful?

  1. BKC Console

Start connecting with Bitkub NEXT

Learn how to connect authentication with Bitkub NEXT by following our simple step.

Last updated 1 year ago

Was this helpful?

Connect your authentication process seamlessly with Bitkub NEXT using the essential key below:

  1. ⚙️

  2. ⚙️

  3. ⚙️

Overview step

  1. Create a constant file to store your project ID, web API Key, and Client ID. The credentials are essential for establishing a secure connection with Bitkub NEXT

  2. create an OAuth callback to handle the authentication process. This callback will enable users to login to your application using their Bitkub NEXT credentials. Implement the necessary logic to securely authenticate users and manage their session

1. Configuration

1. Create a Constant file

// Depend on your env name key 
const projectId = process.env.NEXT_PUBLIC_BITKUB_NEXT_PROJECT_ID ?? ''
const webApiKey = process.env.NEXT_PUBLIC_BITKUB_NEXT_WEB_API_KEY ?? ''
const clientId = process.env.NEXT_PUBLIC_BITKUB_NEXT_CLIENT_ID ?? ''

export {
	projectId,
	webApiKey,
	clientId
}

2. Create Context Provider file

  • import constants

  • import useBitkubNextSDK, BitkubNextSDK, OAuth2ConnectMode

  • Call useBitkubNextSDK with constants

  • Export useContext, Provider

3. Add BitkubNextSdkContextProvider as HOC of the app (Top level)

import { createContext, useContext } from 'react'
import { 
BitkubNextSDK, 
useBitkubNextSDK, 
OAuth2ConnectMode,
} from "@bitkub-blockchain/sdk-client-js"

import { projectId, webApiKey, clientId } from '../constants'

const BitkubNextSdkContext = createContext<BitkubNextSDK | null>(null);

const BitkubNextSdkContextProvider: React.FC = ({ children }) => {
    const { bitkubNextSDK } = useBitkubNextSDK(projectId, webApiKey, clientId, OAuth2ConnectMode.POPUP)

	return (
	  <BitkubNextSdkContext.Provider value={bitkubNextSDK}>
           {children}
         </BitkubNextSdkContext.Provider>
        )
}

export const useBitkubNextSdkContext = () => useContext(BitkubNextSdkContext)

export default BitkubNextSdkContextProvider

2. Usage

  1. Create an OAuth callback page (www.yourdomain.com/oauth/callback)

  • Import useBitkubNextContext

  • Call bitkubNext.resolveCodeFromLogin with URL

import { NextPage } from "next"
import { useRouter } from "next/router"
import { useEffect } from "react"
import { useBitkubNextSdkContext } from "../../contexts/BitkubNextContext"

const Page: NextPage = () => {
  const bitkubNext = useBitkubNextSdkContext()
  const router = useRouter()

  useEffect(() => {
    if (bitkubNext && router.query && Object.keys(router.query).length > 0) {
      bitkubNext.resolveCodeFromLogin(window.location.origin)
    }
  }, [bitkubNext, router.query])

  return null;
};

export default Page;

2. Handle login

  • Import useBitkubNextContext

  • implement bitkubNext.login with redirect URL that matched BKC config

const HomePage: NextPage = () => {
  const bitkubNext = useBitkubNextSdkContext()
  const accessToken = bitkubNext?.useAccessToken() ?? ""

  const handleLogin = () => bitkubNext?.login(`${window.location.origin}/oauth/callback`)
  const handleGetInfo = () => bitkubNext?.getInfo()

  return (
    <div>
      {!accessToken ? (
        <button onClick={handleLogin}>Login</button>
      ) : (
        <button onClick={handleGetInfo}>Get User Info</button>
      )}
    </div>
  );
};

📱
Project ID
Web API Key
Client ID
Configuration:
Usage: