Zuplo logo
Back to all articles
JWT API Authentication

Smart API routing by Auth0 JWT Contents

Josh Twist
March 17, 2022
1 min read

Learn how to add smart routing based on token claims to your API authentication.

We continue with the example from this post and add smart routing based on claims in the token.

Length: 2 minutes

Here's the function handler we create to do the smart routing

TypeScriptts
import { ZuploContext, ZuploRequest } from "@zuplo/runtime";

export default async function (request: ZuploRequest, context: ZuploContext) {
    const data = request.user.data;
    if (data["https://example.com/claim1/"] === "this-is-a-claim"){
        return fetch("https://example.com");
    }
    else {
        return fetch(`https://ecommerce-legacy.zuplo.io/objects?type=products&id=${request.params.productId});
    }
}