Zuplo logo
Back to all articles
March 17, 2022
3 min read

Smart API routing by Auth0 JWT Contents

Josh Twist
Josh TwistCo-founder & CEO

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

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});
    }
}

Questions? Let's chat

Join our community to discuss API integration and get help from our team and other developers.

OPEN DISCORD
51members online