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
Method | Description |
---|---|
async OktoClient.loginUsingJWTAuthentication | Authenticates user using JWT token |
Login Using JWT
asyncOktoClient.loginUsingJWTAuthentication(jwtToken: string)
authenticates users
using JWT tokens and establishes their session.
Parameters
Parameter | Type | Description | Required |
---|---|---|---|
jwtToken | string | The JWT token for authentication | Yes |
Response
Success Response
Field Name | Type | Description |
---|---|---|
result | Promise<Address> | Returns the user's Smart Wallet Address on successful login |
Important
Before using JWT authentication, ensure you have:
- Set up JWT verification with Okto
- Created a verification endpoint that Okto can call
- Generated a valid JWT token with the required user identification