KindeK
Kinde•17mo ago•
7 replies
Otis

`onRedirectCallback` receiving `undefined` value in Remix

I am working from the Kinde Remix SDK documentation: https://docs.kinde.com/developer-tools/sdks/backend/remix-sdk/

I have the following code:
// app/routes/kinde-auth.$index.tsx
import { api } from "convex/_generated/api";
import { client } from "~/lib/convex.server";
import { handleAuth } from "@kinde-oss/kinde-remix-sdk";
import { LoaderFunctionArgs } from "@remix-run/node";

export async function loader({ params, request }: LoaderFunctionArgs) {
  return await handleAuth(request, params.index, {
    onRedirectCallback: ({ user }) => {
      console.log('🔥', user);
      return client.mutation(api.users.addUser, {
      userId: user.id,
    })
    },
  });
}


The user is redirected to Kinde just fine but the onRedirectCallback fails with the following error:
🔥 undefined
TypeError: Cannot read properties of undefined (reading 'id')
    at Object.onRedirectCallback (/Users/otis/Developer/vtt.tools/app/routes/kinde-auth.$index.tsx:11:20)
    at file:///Users/otis/Developer/vtt.tools/node_modules/@kinde-oss/kinde-remix-sdk/dist/index.js:1:3438
    at async loader (/Users/otis/Developer/vtt.tools/app/routes/kinde-auth.$index.tsx:7:10)
    at async Object.callRouteLoader (/Users/otis/Developer/vtt.tools/node_modules/@remix-run/server-runtime/dist/data.js:66:16)
    at async /Users/otis/Developer/vtt.tools/node_modules/@remix-run/router/dist/router.cjs.js:4230:21
    at async callLoaderOrAction (/Users/otis/Developer/vtt.tools/node_modules/@remix-run/router/dist/router.cjs.js:4295:16)
    at async Promise.all (index 1)
    at async callDataStrategyImpl (/Users/otis/Developer/vtt.tools/node_modules/@remix-run/router/dist/router.cjs.js:4170:17)
    at async callDataStrategy (/Users/otis/Developer/vtt.tools/node_modules/@remix-run/router/dist/router.cjs.js:3703:19)
    at async loadRouteData (/Users/otis/Developer/vtt.tools/node_modules/@remix-run/router/dist/router.cjs.js:3678:19)
    at async queryImpl (/Users/otis/Developer/vtt.tools/node_modules/@remix-run/router/dist/router.cjs.js:3523:20)
    at async Object.queryRoute (/Users/otis/Developer/vtt.tools/node_modules/@remix-run/router/dist/router.cjs.js:3489:18)
    at async handleResourceRequest (/Users/otis/Developer/vtt.tools/node_modules/@remix-run/server-runtime/dist/server.js:361:20)
    at async requestHandler (/Users/otis/Developer/vtt.tools/node_modules/@remix-run/server-runtime/dist/server.js:138:18)
    at async nodeHandler (/Users/otis/Developer/vtt.tools/node_modules/@remix-run/dev/dist/vite/plugin.js:841:27)
    at async /Users/otis/Developer/vtt.tools/node_modules/@remix-run/dev/dist/vite/plugin.js:844:15


I think this may be a bug, or I am missunderstanding the intent of the onRedirectCallback.
Kinde docs
Our developer tools provide everything you need to get started with Kinde.
Remix SDK
Was this page helpful?