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
25 Replies
Hey @Konrad,
Thanks for reaching out.
For the Next.js SDK, you can use the
Sign up and sign in To implement the registration functionality, 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:
You can customize the redirect URL after registration by using the postLoginRedirectURL
prop:
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:
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.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 elegantHey @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.
I mean you can easily test it in a demo app. Just show RegisterLink unconditionally with postLoginRedirect and click it after login
Let me look into this and get back to you tomorrow.
Okay thank you
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.are you using
import {RegisterLink} from "@kinde-oss/kinde-auth-nextjs/components";
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
im also using latest version (2.3.8)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.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
Can react sdk coexist with nextjs sdk in the same project?
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?
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
Hey @Konrad,
I apologise, I am confused still confused as to why you would want to use both the nextjs SDK and react SDK in the same project. Is there a specific use-case you want to solve?
I am willing to guide you on how to best use Kinde's SDKs but I cannot guide you unless its clear to me what you are trying to do.
I can also tell you seem to have a way forward: "I Think i will just copy middleware and modify it to my needs"
I am here to help if need be.
I was referring to this code which obviously is incorrect as nextjs sdk has no such functions - only react sdk does. RegisterLink also ignores if user is already logged in. Customizing middleware or wrapping RegisterLink is the only way forward.
Official SDK simply has no such feature but custom middleware will work fine thanks
GitHub
kinde-auth-nextjs/src/handlers/register.js at main · kinde-oss/kind...
Kinde NextJS SDK - authentication for server rendered apps - kinde-oss/kinde-auth-nextjs
RegisterLink just redirects to register unconditionally and kinde doesn’t handle existing user session internally
I think Peter here might know more about this
As an example go to Shopify.com when you press „Start free trial” it redirects you to register
This is not possible with sdk out of the box
But imo it’s common use case for better onboarding UX
I solved it 😫
I also created a custom middleware that supports my i18n lib
Gist
Kinde Auth + Paraglide-Next
Kinde Auth + Paraglide-Next. GitHub Gist: instantly share code, notes, and snippets.
what I did :
loginPage: pathWithoutLang === '/checkout' ? '/api/auth/register' : '/api/auth/login'
I override loginPage
for /checkout
to point to register endpointso now I get what I wanted + also it will redirect to kinde auth based on my apps language
ngl it took me a good 40-60mins
I ran the middleware code through claude to convert it to typescript 😎
it would be good if the middleware supported
lang
param out of the boxI have passed this feedback to my NextJS and React expert team mate.
Sounds like your issue is resolved.
So @Konrad, is there anything else I can help you with for the moment? - besides the following
language
issue: https://discord.com/channels/1070212618549219328/1282059169763033121/1282209102013137028 - lets continue the conversation on this issue in the other thread).