kinde-oss / kinde-remix-sdk

2 stars 2 forks source link

Documentation issue: onRedirectCallback Functionality in Documentation #17

Closed alexmartinezm closed 1 month ago

alexmartinezm commented 2 months ago

Prerequisites

How can we improve the docs or what is missing?

The current documentation for the onRedirectCallback function appears to be misleading or outdated. Specifically, it suggests that the handleAuth function accepts a third parameter, which can be used to define a callback to be executed after user authentication. However, based on my experience, the handleAuth function only accepts two parameters: request: Request and route: any. This discrepancy makes it difficult to implement the feature as described.

To improve the docs, please either:

  1. Update the example to accurately reflect how to use onRedirectCallback with the current implementation.
  2. Provide an alternative approach if the function signature has changed or if there's another recommended method for executing code post-authentication.

Including a more comprehensive example or a note about any recent changes to the function’s signature would be very helpful.

Provide extra context, such as what you were trying to do and your requirements

I was trying to call the onRedirectCallback function after a user has been successfully authenticated, as per the instructions provided in the documentation. My goal was to execute some custom logic after the authentication step, such as logging user information.

Here’s the specific code I used:

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("This is called after the user is authenticated!", user);
    }
  });
}

Unfortunately, this approach doesn't work because handleAuth seems to only accept two parameters, not three as indicated. My requirement is to be able to execute a function after authentication, and it’s unclear from the documentation how to correctly implement this.

A clear, updated example or additional guidance on handling post-authentication logic would greatly assist developers in using this SDK effectively.

If the docs page already exists, please provide a link

https://docs.kinde.com/developer-tools/sdks/backend/remix-sdk/#call-a-function-after-authentication

peterphanouvong commented 1 month ago

Thanks @alexmartinezm, sorry about that - you're right!

I'll have to merge PR #16 for the documentation to be correct.

peterphanouvong commented 1 month ago

resolved in v1.1.1

alexmartinezm commented 1 month ago

resolved in v1.1.1

Hey @peterphanouvong, I've added a comment on #16. It's solved but returned user is null.

peterphanouvong commented 1 month ago

thanks @alexmartinezm, let me look at it again

peterphanouvong commented 1 month ago

@alexmartinezm would you be able to provide any extra info about your project? Unfortunately I wasn't able to recreate the user being null with some of the code that you provided:

import { LoaderFunctionArgs } from "@remix-run/node";

export async function loader({ params, request }: LoaderFunctionArgs) {
  return await handleAuth(request, params.index, {
    onRedirectCallback: async (props) => {
      if (!props.user) {
        console.error("User not found", props);
        return;
      }

      const { user } = props;
      console.log("user", user);
    },
  });
}

Does your project Error out?

alexmartinezm commented 1 month ago

@alexmartinezm would you be able to provide any extra info about your project? Unfortunately I wasn't able to recreate the user being null with some of the code that you provided:

import { LoaderFunctionArgs } from "@remix-run/node";

export async function loader({ params, request }: LoaderFunctionArgs) {
  return await handleAuth(request, params.index, {
    onRedirectCallback: async (props) => {
      if (!props.user) {
        console.error("User not found", props);
        return;
      }

      const { user } = props;
      console.log("user", user);
    },
  });
}

Does your project Error out?

Hey Peter, I just reverted the Vercel dependencies and now I'm using @remix-run/node instead. However, I still got the same error. Please, see the screenshot below:

image

The rest of the project is quite simple, I don't have any special deps. My package.json:

  "dependencies": {
    "@kinde-oss/kinde-remix-sdk": "^1.1.1",
    "@neondatabase/serverless": "^0.9.4",
    "@remix-run/node": "^2.11.2",
    "@remix-run/react": "^2.11.2",
    "drizzle-orm": "^0.33.0",
    "isbot": "^5.1.17",
    "pino": "^9.3.2",
    "pino-pretty": "^11.2.2",
    "react": "^18.3.1",
    "react-dom": "^18.3.1"
  },

As a final note, I'm using an Email/Password authentication method on Kinde.

alexmartinezm commented 1 month ago

Hey @peterphanouvong, any ideas? Thanks in advance!

peterphanouvong commented 1 month ago

Aw man @alexmartinezm still no luck recreating and trying to copy your setup :( Would you be okay with sending over a github repo with the issue reproduced? That would help us out a lot.

The only thing I can think of is maybe the the code isn't in the file app/routes/kinde-auth.$index.tsx?

alexmartinezm commented 1 month ago

Aw man @alexmartinezm still no luck recreating and trying to copy your setup :( Would you be okay with sending over a github repo with the issue reproduced? That would help us out a lot.

The only thing I can think of is maybe the the code isn't in the file app/routes/kinde-auth.$index.tsx?

Yes, it is placed there. Let me invite you to the repo!

peterphanouvong commented 1 month ago

Hey @alexmartinezm I managed to reproduce it! Looks like its only happening for the bundled version which is weird. I'm going to have a dig and see if I can work out whats going on. Thanks for sending the repo through and sorry for the weird bug!!

alexmartinezm commented 1 month ago

Hey @alexmartinezm I managed to reproduce it! Looks like its only happening for the bundled version which is weird. I'm going to have a dig and see if I can work out whats going on. Thanks for sending the repo through and sorry for the weird bug!!

Oh! I'm glad that you could reproduce it. Thanks for looking into, Peter!

peterphanouvong commented 1 month ago

hey @alexmartinezm should now be fixed in v1.1.3 https://www.npmjs.com/package/@kinde-oss/kinde-remix-sdk/v/1.1.3

alexmartinezm commented 2 weeks ago

hey @alexmartinezm should now be fixed in v1.1.3 https://www.npmjs.com/package/@kinde-oss/kinde-remix-sdk/v/1.1.3

Hey there! Didn't have a chance to check the latest version. Unfortunately, still now working.

I made a fresh package install but the props from onRedirectCallback are undefined.

alexmartinezm commented 2 weeks ago

Forget it, I had to clean the pnpm registry to make it work. Thanks!