K
Kinde2mo ago
Konrad

Redirect to register instead of login?

I have "Start free trial" button on my page. It redirects to /checkout and /checkout is protected by the middleware. But the problem is it redirects user to login instead of register. How can I make it redirect to register? I use Next.js SDK
24 Replies
Oli - Kinde
Oli - Kinde2mo ago
Hey @Konrad, Thanks for reaching out. For the Next.js SDK, you can use the RegisterLink component to redirect users to the registration page instead of the login page.
Sign up and sign in To implement the registration functionality, you can use the RegisterLink component provided by the SDK. Here's how you can use it:
import {RegisterLink} from "@kinde-oss/kinde-auth-nextjs/components";

<RegisterLink>Sign up</RegisterLink>
import {RegisterLink} from "@kinde-oss/kinde-auth-nextjs/components";

<RegisterLink>Sign up</RegisterLink>
You can customize the redirect URL after registration by using the postLoginRedirectURL prop:
<RegisterLink postLoginRedirectURL="/checkout">Sign up</RegisterLink>
<RegisterLink postLoginRedirectURL="/checkout">Sign up</RegisterLink>
This will redirect the user to the /checkout page after they have completed the registration process. If you want to implement this programmatically instead of using the component, you can use the register function:
import {useKindeAuth} from "@kinde-oss/kinde-auth-nextjs";

const {register} = useKindeAuth();

// In your component or event handler
register();
import {useKindeAuth} from "@kinde-oss/kinde-auth-nextjs";

const {register} = useKindeAuth();

// In your component or event handler
register();
Remember to update your middleware to allow access to the registration page. You might need to adjust your middleware configuration to ensure it doesn't redirect unauthenticated users away from the registration process.
Konrad
Konrad3w ago
Getting back to this: - <RegisterLink postLoginRedirectURL="/checkout">Sign up</RegisterLink> - the problem is after user logs in and I press it again then the user is still redirected to register page... so this solution won't work and having if everywhere would be far from elegant
Oli - Kinde
Oli - Kinde3w ago
Hey @Konrad, Are you able to record the issue where "user logs in and I press it again then the user is still redirected to register page."? This will help my team replicate the issue and troubleshoot the issue easier.
Konrad
Konrad3w ago
I mean you can easily test it in a demo app. Just show RegisterLink unconditionally with postLoginRedirect and click it after login
Oli - Kinde
Oli - Kinde3w ago
Let me look into this and get back to you tomorrow.
Konrad
Konrad3w ago
Okay thank you
Oli - Kinde
Oli - Kinde2w ago
Hey @Konrad, I am struggling to reproduce this. When I click the <RegisterLink after I am logged in, I am redirected to the postLoginRedirectURL. I am sure I have not setup my app the same way you did. So if you could send a recording or a code snippet of where you experience this issue, that would help my team and I reproduce and troubleshoot this issue.
Konrad
Konrad7d ago
are you using import {RegisterLink} from "@kinde-oss/kinde-auth-nextjs/components";
Konrad
Konrad7d ago
No description
Konrad
Konrad7d ago
It has to be full URL i see, but even with a full url it doesnt work... I stay at register page i use custom domain too I will just create my own wrapper component I think because this is getting tiresome also This doesn't work. register is not part of nextjs specific package
import {useKindeAuth} from "@kinde-oss/kinde-auth-nextjs";

const {register} = useKindeAuth();

// In your component or event handler
register();
import {useKindeAuth} from "@kinde-oss/kinde-auth-nextjs";

const {register} = useKindeAuth();

// In your component or event handler
register();
im also using latest version (2.3.8)
Oli - Kinde
Oli - Kinde5d ago
yes I am. I was still unable to reproduce your issue. register is part of the React SDK method. Whereas RegisterLink is part of the NextJS SDK.
Oli - Kinde
Oli - Kinde5d ago
Hey @Konrad, I think the best next step would be to post an GitHub issue on our NextJS SDK GitHub repo that outlines the issue you are experiencing. My NextJS expert team mate constantly looks at the issues on the repo and addresses them. Please include as much information as possible on the GitHub issue so my team mate can reproduce the issue and fix it.
GitHub
GitHub - kinde-oss/kinde-auth-nextjs: Kinde NextJS SDK - authentica...
Kinde NextJS SDK - authentication for server rendered apps - kinde-oss/kinde-auth-nextjs
Konrad
Konrad5d ago
Can react sdk coexist with nextjs sdk in the same project?
Oli - Kinde
Oli - Kinde5d ago
It can, but I am wondering why you would want to do that? Are you able to elaborate on what you are trying to do?
Konrad
Konrad4d ago
Just simple thing I described. I Think i will just copy middleware and modify it to my needs From kinde sdk repo I had a person who clicked on “try for free” but he was redirected to login And called me why it doesn’t work So I think UX is not good enough And „don’t have an account „ is not easy to see. I need to see how big sites like YouTube do it
Want results from more Discord servers?
Add your server