https://supertokens.com/ logo
Title
c

Chunkygoo

10/08/2022, 4:47 AM
Im trying to call the backend api using a vanilla axios. I’ve added rid in the headers, and attempting to POST a json object of formfields with an array of objects - email and password (just like how the testing with postman section has specified). However, I keep getting an error when attempting to POST. Essentially I’m trying to create a user without using the sign in/up form. Am I missing some headers etc?
r

rp

10/08/2022, 4:48 AM
Hey!
What’s the error? Also, you should use our axios interceptors
c

Chunkygoo

10/08/2022, 4:55 AM
I did use the interceptors
Do you have an example where I can use axios to POST to signup without using the SignInAndUp component?
r

rp

10/08/2022, 4:59 AM
Well, the supertokens-auth-react SDK exposes several helper functions that you can use. One of them is the signUp function, for example from the emailpassword recipe, there is EmailPassword.signUp
Use that instead of manually calling via axios. Will be easier
c

Chunkygoo

10/08/2022, 4:59 AM
Any docs on that?
What arguments do I need to pass to the function in what form etc
r

rp

10/08/2022, 5:00 AM
No docs yet. Working on it.
But it takes the form field array
So pass the email and password
As two different form fields
With id “email” and “password”
c

Chunkygoo

10/08/2022, 5:06 AM
just like Postman right?
Any headers required?
r

rp

10/08/2022, 5:14 AM
await EmaiPassword.signUp({
  formFields: [{
    id: "email",
    value: "..."
  }, {
    id: "password",
    value: "..."
  }]
})
no special headers required.. the SDK figures it out
c

Chunkygoo

10/08/2022, 5:19 AM
Sounds good I’ll try it
Thank you
Hi, it seems like doing that will set the cookies. Is there a way to simply create users? I am building an admin panel. So what I need is only for it to create the users,.
r

rp

10/08/2022, 6:15 AM
ah ok. In that case, you want to create your own API on the backend which has admin auth as a guard for it, and in that API, call the
EmailPassword.signUp(email, password)
function from the backend SDK. This will just create the user in supertokens without creating cookies.
c

Chunkygoo

10/08/2022, 6:24 AM
Im using python fastapi for the backend
What is the equivalent of EmailPassword.signUp(email, password)?
r

rp

10/08/2022, 6:25 AM
There should be emailpassword.syncio.sign_up
Or emailpassword.asyncio.sign_up
c

Chunkygoo

10/08/2022, 6:30 AM
Does it return the created user?
r

rp

10/08/2022, 6:30 AM
It does
See the reference here supertokens.com/docs/python
c

Chunkygoo

10/08/2022, 6:35 AM
It gives me back EmailPasswordSignUpOkResult
r

rp

10/08/2022, 6:35 AM
Yea. That’s a class which contains the info about the user
c

Chunkygoo

10/08/2022, 6:35 AM
Is there a way where I can see the keys and values of this object?
If I print it, it just prints an object in memory
r

rp

10/08/2022, 6:35 AM
See the reference link I sent above.
c

Chunkygoo

10/08/2022, 6:36 AM
This is all I can find
r

rp

10/08/2022, 6:37 AM
Ouu I see. It’s not explicitly defined in the func signature.
c

Chunkygoo

10/08/2022, 6:39 AM
Thank you
I was also able to print it out using this
from pprint import pprint

    pprint(vars(data))
r

rp

10/08/2022, 6:39 AM
Ah fair enough
c

Chunkygoo

10/08/2022, 1:59 PM
@rp emailpassword.syncio.sign_up does not call the post sign up actions that I have defined right?
r

rp

10/08/2022, 2:00 PM
Well, if the post sign up callback is in the apis config, it wont. If it’s in the functions config, it will
c

Chunkygoo

10/08/2022, 2:00 PM
I have added some actions to be taken upon signing up. It works if I use the form, but not for emailpassword.syncio.sign_up (which is fine)
Can you clarify
I did it the way the docs did
which one is that
r

rp

10/08/2022, 2:00 PM
Yea. The docs says about APIs
So the api override only affects the api call
The function override affects api and functional calls.
If you see the override config, it has two params, apis and functions
Also, apis can call multiple functions. For example the sign up api will call the sign_up function (which you are trying to use above) and the create_new_session function from the session recipe.
Whereas the functions override only affects that individual function and nothing else.
c

Chunkygoo

10/08/2022, 2:15 PM
async def emailpassword_sign_up_post(form_fields: List[FormField],
                                         api_options: EmailPasswordAPIOptions, user_context: Dict[str, Any]):
        # call the default behaviour as show below
        result = await original_emailpassword_sign_up_post(form_fields, api_options, user_context)

        if isinstance(result, EmailPasswordSignUpPostOkResult):
            pass # TODO: some post sign up logic
        
        return result
Is this the "function"?
r

rp

10/08/2022, 2:16 PM
No. This is api override
There is a section in override section called backend function override. See that
c

Chunkygoo

10/08/2022, 2:31 PM
So if I add a post sign up action in api override, it will only be called using the form. Or if I POST to "{apiBaserPath}/auth/signup".
If I use emailpassword.syncio.sign_up, the post sign up will NOT work.
Correct?
However, if I override the emailpassword.syncio.sign_up (as specified in https://supertokens.com/docs/thirdpartyemailpassword/advanced-customizations/backend-functions-override/usage), whenever I call emailpassword.syncio.sign_up or POST to "{apiBaserPath}/auth/signup", they will both call the POST sign up function since the api calls the function
Does that sound right?
r

rp

10/08/2022, 2:37 PM
Correct! Exactly
c

Chunkygoo

10/08/2022, 2:39 PM
Thanks rp
Do you know why I wasnt able to POST using axios?
it gives me a 400 error
r

rp

10/08/2022, 2:40 PM
Well, maybe you didn’t add the correct headers for content type
c

Chunkygoo

10/08/2022, 2:40 PM
Where can I find all the right headers?
I did add rid="thirdpartyemailpassword"
r

rp

10/08/2022, 2:43 PM
Well, just that and content-type=“application/json”
c

Chunkygoo

10/08/2022, 2:44 PM
ok I will try again