Custom link for confirm signup -> redirect problem
Hello 🙂
For the past month I was using this custom url for veryfy email and redirect to page and there login user.
https://<supabaseID>.supabase.co/auth/v1/verify?token={{ .TokenHash }}&type=email&redirect_to=https://<app-page>.com/account-details?type=email&token={{ .TokenHash }}&userEmail={{ .Email }}&otp={{ .Token }}
an this was working for long time. But today I found that this part:
redirect_to=https://<app-page>.com/account-details?type=email&token={{ .TokenHash }}&userEmail={{ .Email }}&otp={{ .Token }}
is cut off from userEmail={{ .Email }}&otp={{ .Token }} and type=email.
is auth/v1/verify changed is past days? because sth i cutting my url and it looks like verify 😉
11 Replies
Can you clarify here what you mean by custom link and where this link was set?
Supabase -> Authentication -> Emails -> Templates -> Confirm signup
I think at the beginning the link was like this: {{ .ConfirmationURL }}
But I need redirect to specific page with parameters so I create my "custom link".
https://<supabaseID>.supabase.co/auth/v1/verify?token={{ .TokenHash }}&type=email&redirect_to=https://<app-page>.com/account-details?type=email&token={{ .TokenHash }}&userEmail={{ .Email }}&otp={{ .Token }}
all this variables {{...}} are available for this template.
All you had to do was pass
redirectTo
in your supabase-js call and leave the {{ .ConfirmationURL }}
as it already handles the redirect_to
part. You changing it to what you have has no guarantee of it continuing to work since you are pointing to a Supabase endpoint.
That string that you manually created is basically trying to do the same thing twice, you have type
and token
twice in that URL, so by all means one would get removed, you also cannot add a query string to a query string. It's probably better if you explain what you are trying to do and then we can assist you better.OK 🙂
I'd just like to say that it worked yesterday, and I implemented it a few months ago.
However, I know it was more of a luck than what Supabase allows.
Okay, what I want to do is, after email verification, I'd like to redirect the user to a specific page and automatically log them in. That's why I needed the OTP parameter and the userEmail and on the target page, I did the following:
const { data, error } = await supabase.auth.verifyOTP({
token: OTP,
type: 'email',
email: userEmail,
});
Two thing here, if you are using
token
you don't require the otp
or email
; example below. The next thing is, are you trying to do this in a SSR framework like NextJS?
this is crazy but I do it in Wized...
I don't want to explain myself, but the app was supposed to be small and neat, hence the low-code. And now it's growing. It's time to rewrite it into something else.
I don't know what Wized it, but note that if it's a server side thing then some of the stuff you've done here can break at any point. If it's just a normal SPA (single page app) then you shouldn't need to modify the link in the email template at all as passing
redirectTo
to the signUp
will just work automatically with the default {{ .ConfirmationURL }}
that was in the email template.So this verifyOTP with token_hash is working like a charm! Many thanks!
As you said, now I'll try go back to .ConfirmationURL
You can't go back to
{{ .ConfirmationURL }}
if you are trying to handle .verifyOTP
with the token_hash
in your own code. However {{ .ConfirmationURL }}
on it's own should sign you in if you are using only @supabase/supabase-js
in your code to make the signUp
requests.
Note I am giving you answers based on the limited information you have provided here, so without knowing anything about your project or your setup some of my advice could end up not working.Sure, thanks you for your time. My "production" is back thanks to our conversation. It's 1:30a, time to log off 😉
Haha I know what you mean about time to log off. We're in similar timezone, you're just 1 hour ahead of me.