Skip to main content
For an SDK-agnostic explanation of JWTs and how verification works—applicable no matter which frontend SDK you use (React, Flutter, Swift, Kotlin, etc.)—see Server-side auth and JWT.

Option 1: Leverage NextAuth

If you are using Next.js, you can easily integrate the NextAuth library with Dynamic to perform server-side verification and then use a session client-side.

Option 2: Leverage Passport.js

We offer an official passport-dynamic extension.

Option 3: Do-It-Yourself Verification

  1. Get the JWT through the Dynamic client’s auth.token property.
  2. Send the authToken to the server as a Bearer token
React Native
import { dynamicClient } from '<path to client file>';

// Access the JWT token
const authToken = dynamicClient.auth.token;

if (authToken) {
  // Send to server for verification
  const response = await fetch("http://localhost:9000/api", {
    headers: {
      Authorization: `Bearer ${authToken}`,
    },
  });
  
  const data = await response.json();
  console.log('Server response:', data);
}
  1. Install the node-jsonwebtoken and jwks-rsa packages on your server
  2. Validate the JWT on your server using the same approach as React (see React tab for server-side validation code)