Hello everyone, I'm redesigning authentication pa...
# support-questions
b
Hello everyone, I'm redesigning authentication pages, and have chosen to use
APIs
with
Axios
directly to authenticate users, I'm having issue with
thirdParty
implementation. the
state
query is missing in my callback page after using axios with url :
...../auth/authorisationurl?thirdPartyId=github
and
GET
method will always redirect to default callback page then it ends by redirection to
signin?error=signin
r
hey! Have you read this blog?
b
Hey there how are you doing ?
Will check
r
im good! thanks. How about you?
b
I don't think i've visited the blog before
r
yea. the blog highlights all the steps needed for a custom UI
b
Fine ty
Hey there
I did read the article and i was missing the
rid
header
I've added the header and still get the same error nb i'm using
axios
@rp Well what i see the difference between my callback and the original callback is a missing
state
query
Copy code
export const useThirdPartyAuth = () => {
  const thirdPartyAuth = (provider: ThirdPartyProviders) => async () => {
    const { data } = await fetchSupertokens<any>({
      headers: {
        rid: "thirdpartyemailpassword",
      },
      url: `authorisationurl?thirdPartyId=${provider}`,
    });
    console.log(data.url);
    if (data.url) {
      window.location.href = data.url;
    }
  };
  return { thirdPartyAuth };
};
This is my function
how ever the callback page always redirect to
localhost:3000/app/auth/signin?error=signin
http://localhost:3000/app/auth/callback/github?code=2d04569ec30aa9510447
this is the callback url however it always ends with the link above
r
hey! Im not exactly sure about what you are trying to do here. the result of calling
/authorisationurl
will be a URL to the provider's site. To that, you need to append the redirect_uri query param before redirecting the user (As the blog says). Then the social provider will redirect the user back to your site (on /auth/callback/github for example). On this page, you need to call the
/signinup
POST API (as shown in the article). The input to that API should be the provider ID and the code sent by the provider.
b
even with that it is not working
however i added a new query
r
what is the issue? can you show me the error mesage?
b
&state=d2d68fe8094519207d781
and everything is just fine
r
you shouldn't have to do that.
b
Was just experemnting
r
i see.
does github complain about missing state?
b
That's the issue I don't have any error to track
The url just changes from
http://localhost:3000/app/auth/callback/github?code=2d04569ec30aa9510447
to`signin=error`
r
i see. Oh, so you are using our auth-react SDK?
and making your own UI from that?
b
Yes i kept the config and everything
I took the apis and called them instead of supertokens with custom UI
r
oh i see. They yea.. this is expected cause when you get back to /auth/callback/github, then our SDK checks for the state (which it adds if you use the pre built UI)
So what you want to do is to disable the default implementation in the callback page as well, and then add your own logic there to call the signinup API
b
Wait i didn't tell you i kept the default callback page
r
righrt yea.. don't do that
that will cause an issue like the one you are seeing
I'll tell you what
which version of the auth-react SDK are you using?
b
Yes go ahead please
b
0.18.7
r
Then it will all work even with the default callback UI
You can upgrade to the latest versino of the SDK for this functioun
and then when the user clicks on the social provider's button, then you can call that function like this:
Copy code
<button onClick={() => {
   ThirdPartyEmailPassword.redirectToThirdPartyLogin({thirdPartyId: "github"})
}}/>
And this will do everything you are doing manually (like calling the authorisation API, adding the redirect_uri etc..) and take the user to github. Then when the user comes back to your app, the default callback screen should work
We recently added a bunch of these helper functions to the SDK for custom UI building. But have yet to document them.
b
Alrighty
r
be sure to check the changelog thought. Quite a few changes since 0.18
b
Yes i should pay attention to that, thanks @rp have a nice day
r
You too! Lmk if any issues
2 Views