Smart API routing by Auth0 JWT Contents

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 chatOPEN DISCORD
0members online

Designed for Developers, Made for the Edge