Okto Docs
JWT

JWT Authentication

Authenticate users via JWT using Okto's NextJS SDK with loginUsingJWTAuthentication method for secure, token-based session management.

The loginUsingJWTAuthentication() method authenticates users using JWT tokens. It verifies the JWT token, creates an authentication payload, and sends it to the Okto chain. Upon successful authentication, it updates the user session.

Example

import { useOkto } from '@okto_web3/react-sdk';
 
function JwtAuthentication() {
const oktoClient = useOkto(); 
 
    async function handleJwtLogin(jwtToken: string) {
        try {
            const user = await oktoClient.loginUsingJWTAuthentication(jwtToken); 
            console.log("Login successful:", user);
        } catch (error) {
            console.error("Login failed:", error);
        }
    }
 
    return (
        <div>
            {/* Your JWT token generation/retrieval UI here */}
            <button onClick={() => handleJwtLogin("your-jwt-token")}>
                Login with JWT
            </button>
        </div>
    );
 
}

Note

For error handling: - Use the error code to debug issues. Check out the SDK errors and warnings documentation - For help, navigate to the troubleshooting guide to contact support

Method Overview

MethodDescription
async OktoClient.loginUsingJWTAuthenticationAuthenticates user using JWT token

Login Using JWT

async

OktoClient.loginUsingJWTAuthentication(jwtToken: string) authenticates users using JWT tokens and establishes their session.

Parameters

ParameterTypeDescriptionRequired
jwtTokenstringThe JWT token for authenticationYes

Response

Success Response

Field NameTypeDescription
resultPromise<Address>Returns the user's Smart Wallet Address on successful login

Important

Before using JWT authentication, ensure you have:

  1. Set up JWT verification with Okto
  2. Created a verification endpoint that Okto can call
  3. Generated a valid JWT token with the required user identification